function field_entity_view_mode_rename in Entity view modes 7
Implements hook_entity_view_mode_rename() on behalf of core field module.
File
- ./
entity_view_mode.module, line 220
Code
function field_entity_view_mode_rename($entity_type, $view_mode_old, $view_mode_new) {
$entity_info = entity_get_info($entity_type);
foreach (array_keys($entity_info['bundles']) as $bundle) {
// Update all field bundle settings for the renamed view mode.
$settings = field_bundle_settings($entity_type, $bundle);
$changed = FALSE;
if (isset($settings['view_modes'][$view_mode_old])) {
$settings['view_modes'][$view_mode_new] = $settings['view_modes'][$view_mode_old];
unset($settings['view_modes'][$view_mode_old]);
$changed = TRUE;
}
if (isset($settings['extra_fields']['display'][$view_mode_old])) {
$settings['extra_fields']['display'][$view_mode_new] = $settings['extra_fields']['display'][$view_mode_old];
unset($settings['extra_fields']['display'][$view_mode_old]);
$changed = TRUE;
}
if ($changed) {
field_bundle_settings($entity_type, $bundle, $settings);
}
// Update all field instance display settings for the renamed view mode.
$instances = field_read_instances(array(
'entity_type' => $entity_type,
'bundle' => $bundle,
));
foreach ($instances as $instance) {
// Remove the view mode settings from all configured field instances.
if (isset($instance['display'][$view_mode_old])) {
$instance['display'][$view_mode_new] = $instance['display'][$view_mode_old];
field_update_instance($instance);
}
}
}
}