I have been creating some custom entities to Drupal 8 and they pretty much work as expected but a small thing of getting any value of a field.
Lets say I have basefielddefinition like this:
$fields['level'] = BaseFieldDefinition::create('integer')->setLabel(t('Level'))
->setDescription(t('Level of the event.'))
->setSettings(array(
'max_length' => 10,
'text_processing' => 0,
))
->setDefaultValue(1);
It works as expected and the field I have in SQL looks pretty much like this:
level
int(11) DEFAULT NULL,
But I seem to be unable to get the value of the field itself with any logical operation.
If I try this (in member method) $this->get('level')->value
I get a String no matter what is the type of the field. Is there an actual way to get the data in correct type or do I need to start creating a huge typecast device somewhere here?
I tried going a lot deeper with the TypedDataInterface
but could not find a correct way to get the typed data from there. Also if it is somehow doable there I would really like to point out that, for me at least coming from strongly typed languages, it would seem to logically be the first thing one wants to do, not something that needs to be accessed trough a huge load of different methods. Also isn’t that what PDO is for, getting rightly typed data from the SQL in the first place?