Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By swentel on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Description:
The field_attach_[CRUD]_bundle functions have been moved from Field API to Entity API as managing of bundles should be done by the entity system.
D7
// Create
field_attach_create_bundle('node', $type->type);
// Rename
field_attach_rename_bundle('node', $type->old_type, $type->type);
// Delete
field_attach_delete_bundle('node', $name);
D8
// Create
\Drupal::entityManager()->onBundleCreate('node', $type->type);
// Rename
\Drupal::entityManager()->onBundleRename('node', $type->old_type, $type->type);
// Delete
\Drupal::entityManager()->onBundleDelete('node', $name);
Additionally, the hooks are renamed as well:
D7
// Act on creating a bundle.
function hook_field_attach_create_bundle($entity_type, $bundle) {
}
// Act on renaming a bundle.
function hook_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {
}
// Act on deleting a bundle.
function hook_field_attach_delete_bundle($entity_type, $bundle, $instances) {
}
D8
// Act on creating a bundle.
function hook_entity_bundle_create($entity_type, $bundle) {
}
// Act on renaming a bundle.
function hook_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
}
// Act on deleting a bundle.
// Instances of a bundle are not passed anymore as an argument. If you need
// them, you have to call them yourself.
// @see field_entity_bundle_delete()
function hook_entity_bundle_delete($entity_type, $bundle) {
}
Note When config entity extends ConfigEntityBundleBase
then its content entities are handled automatically for this
Impacts:
Module developers