1 field.module field_entity_view_mode_update($view_mode, $entity_type)

Implements hook_entity_view_mode_update().

File

core/modules/field/field.module, line 1321
Attach custom data fields to Backdrop entities.

Code

function field_entity_view_mode_update($view_mode, $entity_type) {
  module_load_include('inc', 'field_ui', 'field_ui.admin');
  $entity_info = entity_get_info($entity_type);
  $view_mode_name = $view_mode['machine_name'];

  if (!empty($view_mode['enabled_bundles'])) {
    foreach ($view_mode['enabled_bundles'] as $bundle => $value) {
      $bundle_settings = field_bundle_settings($entity_type, $bundle);

      // Display a message for each display mode newly configured to use custom
      // settings.
      $view_mode_settings = field_view_mode_settings($entity_type, $bundle);
      if (!empty($value) && empty($view_mode_settings[$view_mode_name]['custom_settings'])) {
        $path = _field_ui_bundle_admin_path($entity_type, $bundle) . "/display/$view_mode_name";
        backdrop_set_message(t('The %view_mode @entity_type @bundle display mode now uses custom display settings copied from the default display mode. You might want to <a href="@url">configure them</a>.', array(
          '%view_mode' => $view_mode['label'],
          '@entity_type' => $entity_info['label'],
          '@bundle' => $entity_info['bundles'][$bundle]['label'],
          '@url' => url($path, array('query' => backdrop_get_destination())),
        )));
        // Initialize the newly customized display mode with the display settings
        // from the default display mode.
        _field_ui_add_default_view_mode_settings($entity_type, $bundle, $view_mode_name, $bundle_settings);
      }

      // Save updated bundle settings.
      $bundle_settings['view_modes'][$view_mode_name]['custom_settings'] = !empty($value);
      field_bundle_settings($entity_type, $bundle, $bundle_settings);
    }
  }
}