hook_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle, array $base_field_definitions)
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\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 1724
- Hooks and documentation related to entities.
Code
1 2 3 4 5 6 7 8 9 10 11 | 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 = array (); $fields [ 'mymodule_text_more' ] = BaseFieldDefinition::create( 'string' ) ->setLabel(t( 'More text' )) ->setComputed(TRUE) ->setClass( '\Drupal\mymodule\EntityComputedMoreText' ); return $fields ; } } |
Please login to continue.