diff --git a/core/lib/Drupal/Core/Field/BundleFieldDefinition.php b/core/lib/Drupal/Core/Field/BundleFieldDefinition.php index 86390fa606..a3c6a85e13 100644 --- a/core/lib/Drupal/Core/Field/BundleFieldDefinition.php +++ b/core/lib/Drupal/Core/Field/BundleFieldDefinition.php @@ -3,7 +3,22 @@ namespace Drupal\Core\Field; /** - * A class for defining bundle fields. + * A class for defining entity bundle fields. + * + * This class defines a builder for both a field definition and a field storage + * definition for a bundle field. A bundle field is different from a base field + * in that it may exist only for one or more bundles of an entity type. + * + * Bundle fields can defined in code using hook_entity_bundle_field_info or by + * implementing FieldableEntityInterface::bundleFieldDefinitions. Once a bundle + * field definition has been defined, if it is not computed and requires storage + * hook_entity_field_storage_info must also be implemented. + * + * @see \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions + * @see \Drupal\Core\Field\FieldDefinitionInterface + * @see \Drupal\Core\Field\FieldStorageDefinitionInterface + * @see hook_entity_bundle_field_info + * @see hook_entity_field_storage_info */ class BundleFieldDefinition extends BaseFieldDefinition { diff --git a/core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php b/core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php index 380c1e66ed..6a4610da66 100644 --- a/core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php +++ b/core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php @@ -3,7 +3,7 @@ namespace Drupal\system\Tests\Entity; use Drupal\Core\Field\BaseFieldDefinition; -use Drupal\entity_test\FieldStorageDefinition; +use Drupal\entity\BundleFieldDefinition; /** * Provides some test methods used to update existing entity definitions. @@ -203,7 +203,7 @@ protected function removeBaseFieldIndex() { * (optional) The field type for the new field. Defaults to 'string'. */ protected function addBundleField($type = 'string') { - $definitions['new_bundle_field'] = FieldStorageDefinition::create($type) + $definitions['new_bundle_field'] = BundleFieldDefinition::create($type) ->setName('new_bundle_field') ->setLabel(t('A new bundle field')) ->setTargetEntityTypeId('entity_test_update'); diff --git a/core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module b/core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module index 50bf3e3bb1..642fe1272e 100644 --- a/core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module +++ b/core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module @@ -7,7 +7,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; -use Drupal\entity_test\FieldStorageDefinition; +use Drupal\entity\BundleFieldDefinition; use Drupal\entity_test\Entity\EntityTestMulRev; /** @@ -49,7 +49,7 @@ function entity_schema_test_entity_base_field_info(EntityTypeInterface $entity_t */ function entity_schema_test_entity_field_storage_info(EntityTypeInterface $entity_type) { if ($entity_type->id() == 'entity_test') { - $definitions['custom_bundle_field'] = FieldStorageDefinition::create('string') + $definitions['custom_bundle_field'] = BundleFieldDefinition::create('string') ->setName('custom_bundle_field') ->setLabel(t('A custom bundle field')) ->setTargetEntityTypeId($entity_type->id()); diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php index 7fe9ce2112..de4532d94b 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php @@ -4,7 +4,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; -use Drupal\entity_test\FieldStorageDefinition; +use Drupal\Core\Field\FieldStorageDefinitionInterface; /** * Defines a test entity class for base fields display. @@ -77,7 +77,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['test_display_multiple'] = BaseFieldDefinition::create('text') ->setLabel(t('A field with multiple values')) - ->setCardinality(FieldStorageDefinition::CARDINALITY_UNLIMITED) + ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) ->setDisplayOptions('view', [ 'type' => 'text_default', 'weight' => 12,