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.

CommentFileSizeAuthor
#2 support_a_data_key-2633914-2.patch3.62 KBmglaman
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Status: Active » Needs review
FileSize
3.62 KB

Here'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.

Eyal Shalev’s picture

Shouldn't the above functionality relay on entity keys?

What if the entity uses a different semantic then data?

bojanz’s picture

Status: Needs review » Closed (won't fix)

I think the gains here are too small, most entities don't have and should have a bucket of serialized data attached.