function hook_entity_bundle_field_info
Provides field definitions for a specific bundle within an entity type.
Bundle fields either have to override an existing base field, or need to provide a field storage definition via hook_entity_field_storage_info() unless they are computed.
@todo WARNING: This hook will be changed in https://www.drupal.org/node/2346347.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition.
string $bundle: The bundle.
\Drupal\Core\Field\FieldDefinitionInterface[] $base_field_definitions: The list of base field definitions for the entity type.
Return value
\Drupal\Core\Field\FieldDefinitionInterface[] An array of bundle field definitions, keyed by field name.
See also
hook_entity_base_field_info_alter()
hook_entity_field_storage_info()
hook_entity_field_storage_info_alter()
hook_entity_bundle_field_info_alter()
\Drupal\Core\Field\FieldDefinitionInterface
\Drupal\Core\Field\FieldDefinition
\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()
Related topics
8 functions implement hook_entity_bundle_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.
- ContentModerationHooks::entityBundleFieldInfo in core/
modules/ content_moderation/ src/ Hook/ ContentModerationHooks.php  - Implements hook_entity_bundle_field_info().
 - content_moderation_entity_bundle_field_info in core/
modules/ content_moderation/ content_moderation.module  - Implements hook_entity_bundle_field_info().
 - EntitySchemaTestHooks::entityBundleFieldInfo in core/
modules/ system/ tests/ modules/ entity_schema_test/ src/ Hook/ EntitySchemaTestHooks.php  - Implements hook_entity_bundle_field_info().
 - EntityTestExtraHooks::entityBundleFieldInfo in core/
modules/ system/ tests/ modules/ entity_test_extra/ src/ Hook/ EntityTestExtraHooks.php  - Implements hook_entity_bundle_field_info().
 - entity_schema_test_entity_bundle_field_info in core/
modules/ system/ tests/ modules/ entity_schema_test/ entity_schema_test.module  - Implements hook_entity_bundle_field_info().
 
File
- 
              core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 1989  
Code
function hook_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
  // Add a property only to nodes of the 'article' bundle.
  if ($entity_type->id() == 'node' && $bundle == 'article') {
    $fields = [];
    $storage_definitions = mymodule_entity_field_storage_info($entity_type);
    $fields['mymodule_bundle_field'] = FieldDefinition::createFromFieldStorageDefinition($storage_definitions['mymodule_bundle_field'])->setLabel(t('Bundle Field'));
    return $fields;
  }
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.