function hook_entity_base_field_info

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_base_field_info()
  2. 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_base_field_info()
  3. 11.x 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

27 functions implement hook_entity_base_field_info()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

ContactStorageTestHooks::entityBaseFieldInfo in core/modules/contact/tests/modules/contact_storage_test/src/Hook/ContactStorageTestHooks.php
Implements hook_entity_base_field_info().
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().
ContentModerationHooks::entityBaseFieldInfo in core/modules/content_moderation/src/Hook/ContentModerationHooks.php
Implements hook_entity_base_field_info().
ContentTranslationHooks::entityBaseFieldInfo in core/modules/content_translation/src/Hook/ContentTranslationHooks.php
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().

... See full list

File

core/lib/Drupal/Core/Entity/entity.api.php, line 1942

Code

function hook_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
  if ($entity_type->id() == 'node') {
    $fields = [];
    $fields['my_module_text'] = BaseFieldDefinition::create('string')->setLabel(t('The text'))
      ->setDescription(t('A text property added by my_module.'))
      ->setComputed(TRUE)
      ->setClass('\\Drupal\\my_module\\EntityComputedText');
    return $fields;
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.