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 1661
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;
  }
}
doc_Drupal
2016-10-29 09:17:55
Comments
Leave a Comment

Please login to continue.