Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There's quite a few entities which utilize a data property that stores generic data. It'd be a nice feature if the Entity API module could check for a "data" key, or some kind of flag, and add
$fields['data'] = BaseFieldDefinition::create('map')
->setLabel(t('Data'))
->setDescription(t('A serialized array of additional data.'));
to the EntityKeysFieldsTrait::entityKeysBaseFieldDefinitions method.
Comment | File | Size | Author |
---|---|---|---|
#2 | support_a_data_key-2633914-2.patch | 3.62 KB | mglaman |
Comments
Comment #2
mglamanHere's a go. Add new trait EntityDataFieldTrait that has method entityDataFieldDefinition which just adds the "data" field definition by reference to the based array of field definitions. Attached is a test, too.
Comment #3
Eyal ShalevShouldn't the above functionality relay on entity keys?
What if the entity uses a different semantic then
data
?Comment #4
bojanz CreditAttribution: bojanz at Centarro commentedI think the gains here are too small, most entities don't have and should have a bucket of serialized data attached.