class Bundle
Same name in this branch
- 11.x core/modules/views/src/Plugin/views/filter/Bundle.php \Drupal\views\Plugin\views\filter\Bundle
Same name and namespace in other branches
- 10 core/modules/views/src/Plugin/views/filter/Bundle.php \Drupal\views\Plugin\views\filter\Bundle
- 9 core/modules/views/src/Plugin/views/filter/Bundle.php \Drupal\views\Plugin\views\filter\Bundle
- 8.9.x core/modules/views/src/Plugin/views/filter/Bundle.php \Drupal\views\Plugin\views\filter\Bundle
- main core/modules/views/src/Plugin/views/filter/Bundle.php \Drupal\views\Plugin\views\filter\Bundle
- main core/lib/Drupal/Core/Entity/Attribute/Bundle.php \Drupal\Core\Entity\Attribute\Bundle
Defines an attribute for registering a bundle class.
This makes an EntityInterface class under a module's Entity namespace discoverable as a bundle class for an entity type. Because entity bundle information from attribute discovery is added after 'entity_bundle_info' hooks have run and before 'entity_bundle_info_alter' hooks have run, there are two general use cases for using this attribute:
- Alter bundle information provided by 'entity_bundle_info' hooks, in which case any attribute class properties that are optional will not be set or override existing values.
- Provide bundle information in lieu of using the hooks, in which case the label property should be set. It is possible to define bundles with this attribute for entity types that do not have a 'bundle_entity_type' defined. For entity types that do have a 'bundle_entity_type' defined, it is not possible to use this attribute to designate a bundle class for nonexistent bundle entities.
If there are multiple bundle classes with attributes specifying the same entity type bundle, 'entity_bundle_info_alter' hooks can be implemented to specify which bundle class will be used.
Attributes
#[\Attribute(\Attribute::TARGET_CLASS)]
Hierarchy
- class \Drupal\Component\Plugin\Attribute\AttributeBase implements \Drupal\Component\Plugin\Attribute\AttributeInterface
- class \Drupal\Component\Plugin\Attribute\Plugin extends \Drupal\Component\Plugin\Attribute\AttributeBase
- class \Drupal\Core\Entity\Attribute\EntityType extends \Drupal\Component\Plugin\Attribute\Plugin
- class \Drupal\Core\Entity\Attribute\ContentEntityType extends \Drupal\Core\Entity\Attribute\EntityType
- class \Drupal\Core\Entity\Attribute\Bundle extends \Drupal\Core\Entity\Attribute\ContentEntityType
- class \Drupal\Core\Entity\Attribute\ContentEntityType extends \Drupal\Core\Entity\Attribute\EntityType
- class \Drupal\Core\Entity\Attribute\EntityType extends \Drupal\Component\Plugin\Attribute\Plugin
- class \Drupal\Component\Plugin\Attribute\Plugin extends \Drupal\Component\Plugin\Attribute\AttributeBase
Expanded class hierarchy of Bundle
4 files declare their use of Bundle
- EntityTestBundleClassOverrideA.php in core/
modules/ system/ tests/ modules/ entity_test_attribute_bundle_class/ src/ Entity/ EntityTestBundleClassOverrideA.php - EntityTestBundleClassOverrideB.php in core/
modules/ system/ tests/ modules/ entity_test_attribute_bundle_class/ src/ Entity/ EntityTestBundleClassOverrideB.php - EntityTestSubdirBundleClass.php in core/
modules/ system/ tests/ modules/ entity_test_attribute_bundle_class/ src/ Entity/ Subdir/ EntityTestSubdirBundleClass.php - EntityTestWithBundleTypeNewBundle.php in core/
modules/ system/ tests/ modules/ entity_test_attribute_bundle_class/ src/ Entity/ EntityTestWithBundleTypeNewBundle.php
195 string references to 'Bundle'
- BaseFieldOverrideValidationTest::testTargetBundleMustExist in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ BaseFieldOverrideValidationTest.php - Tests that the target bundle of the field is checked.
- block_content_body_field.yml in core/
modules/ block_content/ migrations/ block_content_body_field.yml - core/modules/block_content/migrations/block_content_body_field.yml
- block_content_entity_display.yml in core/
modules/ block_content/ migrations/ block_content_entity_display.yml - core/modules/block_content/migrations/block_content_entity_display.yml
- block_content_entity_form_display.yml in core/
modules/ block_content/ migrations/ block_content_entity_form_display.yml - core/modules/block_content/migrations/block_content_entity_form_display.yml
- Bundle::init in core/
modules/ views/ src/ Plugin/ views/ filter/ Bundle.php - Overrides \Drupal\views\Plugin\views\HandlerBase::init().
File
-
core/
lib/ Drupal/ Core/ Entity/ Attribute/ Bundle.php, line 31
Namespace
Drupal\Core\Entity\AttributeView source
class Bundle extends ContentEntityType {
/**
* Constructs a Bundle attribute object.
*
* @param string $entityType
* The entity type ID.
* @param string|null $bundle
* The bundle ID, or NULL to use entity type ID as the bundle name.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $label
* (optional) The human-readable name of the bundle.
* @param bool|null $translatable
* (optional) A boolean value specifying whether this bundle has translation
* support enabled. If 'translatable' is defined for the bundle by an
* 'entity_bundle_info' hook, using NULL here will prevent that from being
* overridden. Otherwise, NULL is the same as FALSE.
*/
public function __construct(string $entityType, ?string $bundle = NULL, ?TranslatableMarkup $label = NULL, ?bool $translatable = NULL) {
$bundle ??= $entityType;
parent::__construct(id: "{$entityType}:{$bundle}", label: $label, additional: [
'entity_type_bundle_info' => [
$bundle => [
// Setting this here because 'translatable' class property can not
// be NULL.
'translatable' => $translatable,
],
],
]);
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
|---|---|---|---|---|---|
| AttributeBase::$class | protected | property | The class used for this attribute class. | ||
| AttributeBase::$dependencies | protected | property | The dependencies for the attribute class. | ||
| AttributeBase::$provider | protected | property | The provider of the attribute class. | ||
| AttributeBase::getClass | public | function | Gets the class of the attribute class. | Overrides AttributeInterface::getClass | 1 |
| AttributeBase::getDependencies | public | function | Gets the dependencies for this attribute class. | Overrides AttributeInterface::getDependencies | |
| AttributeBase::getId | public | function | Gets the unique ID for this attribute class. | Overrides AttributeInterface::getId | |
| AttributeBase::getProvider | public | function | Gets the name of the provider of the attribute class. | Overrides AttributeInterface::getProvider | |
| AttributeBase::setClass | public | function | Sets the class of the attributed class. | Overrides AttributeInterface::setClass | 1 |
| AttributeBase::setDependencies | public | function | Sets the dependencies for this attribute class. | Overrides AttributeInterface::setDependencies | |
| AttributeBase::setProvider | public | function | Sets the name of the provider of the attribute class. | Overrides AttributeInterface::setProvider | |
| Bundle::__construct | public | function | Constructs a Bundle attribute object. | Overrides ContentEntityType::__construct | |
| EntityType::get | public | function | Gets the value of an attribute. | Overrides AttributeBase::get |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.