On this page
function hook_entity_base_field_info
hook_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type)
Provides custom base field definitions for a content entity type.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition.
Return value
\Drupal\Core\Field\FieldDefinitionInterface[] An array of field definitions, keyed by field name.
See also
hook_entity_base_field_info_alter()
hook_entity_bundle_field_info()
hook_entity_bundle_field_info_alter()
\Drupal\Core\Field\FieldDefinitionInterface
\Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions()
Related topics
- Hooks
- Define functions that alter the behavior of Drupal core.
File
- core/lib/Drupal/Core/Entity/entity.api.php, line 1667
- Hooks and documentation related to entities.
Code
function hook_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
if ($entity_type->id() == 'node') {
$fields = array();
$fields['mymodule_text'] = BaseFieldDefinition::create('string')
->setLabel(t('The text'))
->setDescription(t('A text property added by mymodule.'))
->setComputed(TRUE)
->setClass('\Drupal\mymodule\EntityComputedText');
return $fields;
}
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!entity.api.php/function/hook_entity_base_field_info/8.1.x