You are here

function media_update_7206 in D7 Media 7.4

Same name and namespace in other branches
  1. 7.2 media.install \media_update_7206()
  2. 7.3 media.install \media_update_7206()

Move default file display configurations to the database.

File

./media.install, line 810
Install, update and uninstall functions for the Media module.

Code

function media_update_7206() {
  module_load_include('inc', 'file_entity', 'file_entity.file_api');
  module_load_include('inc', 'ctools', 'includes/export');
  $default_image_styles = array(
    'preview' => 'square_thumbnail',
    'teaser' => 'medium',
    'full' => 'large',
  );

  // Only needed by sites that updated from Media 1.x.
  // @see media_entity_info_alter()
  if (variable_get('media__show_deprecated_view_modes')) {
    $default_image_styles['media_original'] = '';
  }

  // Clear out the ctools cache so that the old default implementations
  // are removed.
  ctools_export_load_object_reset('file_display');
  foreach ($default_image_styles as $view_mode => $image_style) {
    $existing_displays = file_displays_load('image', $view_mode, TRUE);

    // Only insert default config into the database if no existing
    // configuration is found.
    if (!isset($existing_displays['file_image'])) {
      $display_name = 'image__' . $view_mode . '__file_image';
      $display = array(
        'api_version' => 1,
        'name' => $display_name,
        'status' => 1,
        'weight' => 5,
        'settings' => array(
          'image_style' => $image_style,
        ),
        'export_type' => NULL,
      );
      file_display_save((object) $display);
    }
  }
}