Bundle

A bundle is a subtype of a Drupal entity type that shares one set of fields, such as a content type for nodes or a vocabulary for taxonomy terms.

Learn DrupalDrupal glossary

A bundle is a variant of an entity type that has its own set of fields. The node entity type has content types as bundles, such as Article and Basic page; taxonomy terms have vocabularies. The Drupal user guide uses the term entity subtype for the same idea. Some entity types, such as the user, have no bundles.

How bundles work in Drupal 11

An entity type that has bundles names a bundle key. For nodes it is type. The entity type definition links both sides: the node definition sets bundle_entity_type to node_type, and the node_type definition sets bundle_of to node. In code, EntityTypeInterface exposes this through getBundleEntityType() and getBundleOf().

Drupal.org says a bundle is typically a configuration entity that stores what differs between the content entities of a type. The base class is ConfigEntityBundleBase. It refuses to save a changed bundle ID and throws a ConfigNameException. When a bundle is deleted, it also deletes the bundle's view and form display configuration. A bundle name can have at most 32 characters.

The reason bundles matter is fields. Per the user guide, administrators add fields to a subtype, and all entities of that subtype share them. A Vendor content type can have a logo that a Basic page does not.

Example

When a developer creates a node, the bundle goes in as the type value, and bundle() returns it later:

$node = $storage->create(['type' => 'article', 'title' => 'Sample title']);
        $node->bundle(); // 'article'

Here node is the entity type and article is the bundle. In the admin interface the same split appears as content type (Structure › Content types), vocabulary or block type.

Common mistakes

  • Mixing up the entity type and the bundle. A request to "add a field to nodes" is incomplete until it names a bundle, because administrators add fields per subtype.
  • Trying to rename a bundle. Core blocks changing a saved bundle ID. Choose the machine name carefully before the first save.

For marketing and content teams

The user guide notes that the word bundle shows up especially in programmer documentation. In the admin interface it surfaces as "content type", "vocabulary" or "block type", depending on what is being structured. When a developer asks which bundle a request is for, the answer is the name of the content type, vocabulary or block type that should get the new field.

Sources

Questions about Bundle

A content type is the bundle of one entity type: the node. Taxonomy terms use vocabularies as bundles, and content blocks use block types. So every content type is a bundle, but not every bundle is a content type.

No. Drupal.org lists the user entity type among those with no child bundles. For such a type, the bundle() method on an entity returns the entity type ID instead.

A bundle class is a PHP class for one bundle, so that entities of that bundle load as instances of it and can carry their own methods. A module declares one with hook_entity_bundle_info(), or sets one for another module's bundle with hook_entity_bundle_info_alter(). The Drupal.org change record dates this to Drupal 9.3.

Related terms

All Drupal terms from A to Z