1 field.attach.inc | field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) |
Notify field.module that a bundle was renamed.
Parameters
$entity_type: The entity type to which the bundle is bound.
$bundle_old: The previous name of the bundle.
$bundle_new: The new name of the bundle.
Related topics
File
- core/
modules/ field/ field.attach.inc, line 1314 - Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.
Code
function field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {
// Update field instances.
$prefix = 'field.instance.' . $entity_type;
$instance_config_names = config_get_names_with_prefix("$prefix.$bundle_old.");
foreach ($instance_config_names as $config_name) {
$field_name = str_replace("$prefix.$bundle_old.", '', $config_name);
$instance_old = config("$prefix.$bundle_old.$field_name");
$instance_new = config("$prefix.$bundle_new.$field_name");
$data = $instance_old->get();
$data['bundle'] = $bundle_new;
$instance_new->setData($data);
$instance_new->save();
$instance_old->delete();
}
// Clear the cache.
field_cache_clear();
entity_info_cache_clear();
// Update bundle settings.
$old_config = config("field.bundle.$entity_type.$bundle_old");
$new_config = config("field.bundle.$entity_type.$bundle_new");
$new_config->setData($old_config->get());
$new_config->save();
$old_config->delete();
// Let other modules act on renaming the bundle.
module_invoke_all('field_attach_rename_bundle', $entity_type, $bundle_old, $bundle_new);
}