function hook_entity_bundle_field_info
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_bundle_field_info()
- 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_bundle_field_info()
- 11.x core/lib/Drupal/Core/Entity/entity.api.php \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
4 functions implement hook_entity_bundle_field_info()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- content_moderation_entity_bundle_field_info in core/
modules/ content_moderation/ content_moderation.module - 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().
- entity_test_extra_entity_bundle_field_info in core/
modules/ system/ tests/ modules/ entity_test_extra/ entity_test_extra.module - Implements hook_entity_bundle_field_info().
- field_entity_bundle_field_info in core/
modules/ field/ field.module - Implements hook_entity_bundle_field_info().
1 invocation of hook_entity_bundle_field_info()
- EntityFieldManager::buildBundleFieldDefinitions in core/
lib/ Drupal/ Core/ Entity/ EntityFieldManager.php - Builds field definitions for a specific bundle within an entity type.
File
-
core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 1932
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.