You are here

function field_entity_view_mode_delete in Entity view modes 7

Implements hook_entity_view_mode_delete() on behalf of core field module.

File

./entity_view_mode.module, line 297

Code

function field_entity_view_mode_delete($view_mode, $entity_type) {
  $entity_info = entity_get_info($entity_type);
  $view_mode_name = $view_mode['machine_name'];
  foreach (array_keys($entity_info['bundles']) as $bundle) {

    // Remove all field bundle settings for the deleted view mode.
    $settings = field_bundle_settings($entity_type, $bundle);
    if (isset($settings['view_modes'][$view_mode_name]) || isset($settings['extra_fields']['display'][$view_mode_name])) {
      unset($settings['view_modes'][$view_mode_name]);
      unset($settings['extra_fields']['display'][$view_mode_name]);
      field_bundle_settings($entity_type, $bundle, $settings);
    }

    // Remove all field instance display settings for the deleted 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_name])) {
        unset($instance['display'][$view_mode_name]);
        field_update_instance($instance);
      }
    }
  }
}