You are here

function media_gallery_file_default_displays in Media Gallery 7

Same name and namespace in other branches
  1. 7.2 media_gallery.module \media_gallery_file_default_displays()

Implements hook_file_default_displays().

Provides default display configurations for files displayed in gallery view modes.

See also

file_entity_schema()

File

./media_gallery.module, line 1769

Code

function media_gallery_file_default_displays() {
  $default_displays = array();
  $default_image_styles = array(
    'media_gallery_thumbnail' => 'media_gallery_thumbnail',
    'media_gallery_lightbox' => 'media_gallery_large',
    'media_gallery_detail' => 'media_gallery_large',
    'media_gallery_block_thumbnail' => 'media_gallery_thumbnail',
    'media_gallery_collection_thumbnail' => 'media_gallery_thumbnail',
  );

  // People updating from older versions of Media module will have Styles module
  // formatters enabled at weight 0. By default, we want the following taking
  // precedence, but we do not want to disable the Styles module ones since
  // those might be capable of rendering files not covered by these. Therefore,
  // set these at a lower weight.
  $default_weight = -1;
  foreach ($default_image_styles as $view_mode => $image_style) {

    // Images.
    $display_name = 'image__' . $view_mode . '__file_image';
    $default_displays[$display_name] = (object) array(
      'api_version' => 1,
      'name' => $display_name,
      'status' => 1,
      'settings' => array(
        'image_style' => $image_style,
      ),
      'weight' => $default_weight,
    );

    // YouTube.
    if (module_exists('media_youtube')) {
      if (in_array($view_mode, array(
        'media_gallery_lightbox',
        'media_gallery_detail',
      ))) {

        // Video. Omit settings to use media_youtube_video defaults.
        $display_name = 'video__' . $view_mode . '__media_youtube_video';
        $default_displays[$display_name] = (object) array(
          'api_version' => 1,
          'name' => $display_name,
          'status' => 1,
          'weight' => $default_weight,
        );
      }
      else {

        // Thumbnail.
        $display_name = 'video__' . $view_mode . '__media_youtube_image';
        $default_displays[$display_name] = (object) array(
          'api_version' => 1,
          'name' => $display_name,
          'status' => 1,
          'settings' => array(
            'image_style' => $image_style,
          ),
          'weight' => $default_weight,
        );
      }
    }
  }
  return $default_displays;
}