You are here

function hook_entity_bundle_field_info in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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()

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

3 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.

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 1729
Hooks and documentation related to entities.

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 = array();
    $fields['mymodule_text_more'] = BaseFieldDefinition::create('string')
      ->setLabel(t('More text'))
      ->setComputed(TRUE)
      ->setClass('\\Drupal\\mymodule\\EntityComputedMoreText');
    return $fields;
  }
}