Define custom entity properties.
string $entity_type: The entity type for which to define entity properties.
array An array of property information having the following optional entries:
Drupal\Core\TypedData\TypedDataManager::create()
hook_entity_field_info_alter()
Drupal\Core\Entity\StorageControllerInterface::getPropertyDefinitions()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
function hook_entity_field_info($entity_type) {
if (mymodule_uses_entity_type($entity_type)) {
$info = array();
$info['definitions']['mymodule_text'] = array(
'type' => 'string_item',
'list' => TRUE,
'label' => t('The text'),
'description' => t('A text property added by mymodule.'),
'computed' => TRUE,
'class' => '\\Drupal\\mymodule\\EntityComputedText',
);
if ($entity_type == 'node') {
// Add a property only to entities of the 'article' bundle.
$info['optional']['mymodule_text_more'] = array(
'type' => 'string_item',
'list' => TRUE,
'label' => t('More text'),
'computed' => TRUE,
'class' => '\\Drupal\\mymodule\\EntityComputedMoreText',
);
$info['bundle map']['article'][0] = 'mymodule_text_more';
}
return $info;
}
}