You are here

function hook_entity_base_field_info in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_base_field_info()

Provides custom base field definitions for a content entity type.

Field (storage) definitions returned by this hook must run through the regular field storage life-cycle operations: they need to be properly installed, updated, and uninstalled. This would typically be done through the Entity Update API provided by the entity definition update manager.

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\EntityFieldManagerInterface::getFieldDefinitions()

\Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface

https://www.drupal.org/node/3034742

Related topics

13 functions implement hook_entity_base_field_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

contact_storage_test_entity_base_field_info in core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.module
Implements hook_entity_base_field_info().
content_moderation_entity_base_field_info in core/modules/content_moderation/content_moderation.module
Implements hook_entity_base_field_info().
content_translation_entity_base_field_info in core/modules/content_translation/content_translation.module
Implements hook_entity_base_field_info().
entity_reference_test_entity_base_field_info in core/modules/system/tests/modules/entity_reference_test/entity_reference_test.module
Implements hook_entity_base_field_info().
entity_schema_test_entity_base_field_info in core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module
Implements hook_entity_base_field_info().

... See full list

1 invocation of hook_entity_base_field_info()
EntityFieldManager::buildBaseFieldDefinitions in core/lib/Drupal/Core/Entity/EntityFieldManager.php
Builds base field definitions for an entity type.

File

core/lib/Drupal/Core/Entity/entity.api.php, line 1868
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 = [];
    $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;
  }
}