class Bundle

Same name in this branch
  1. main core/modules/views/src/Plugin/views/filter/Bundle.php \Drupal\views\Plugin\views\filter\Bundle
Same name and namespace in other branches
  1. 11.x core/modules/views/src/Plugin/views/filter/Bundle.php \Drupal\views\Plugin\views\filter\Bundle
  2. 10 core/modules/views/src/Plugin/views/filter/Bundle.php \Drupal\views\Plugin\views\filter\Bundle
  3. 9 core/modules/views/src/Plugin/views/filter/Bundle.php \Drupal\views\Plugin\views\filter\Bundle
  4. 8.9.x core/modules/views/src/Plugin/views/filter/Bundle.php \Drupal\views\Plugin\views\filter\Bundle
  5. 11.x 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

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
193 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

... See full list

File

core/lib/Drupal/Core/Entity/Attribute/Bundle.php, line 31

Namespace

Drupal\Core\Entity\Attribute
View 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,
        ],
      ],
    ]);
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.