You are here

function _media_gallery_controlled_instances in Media Gallery 7

Same name and namespace in other branches
  1. 7.2 media_gallery.install \_media_gallery_controlled_instances()

Returns definitions for instances this modules both creates and deletes.

Parameters

$group: Optional. The group of instances to return. May be 'node' or 'taxonomy_term'. If omitted, returns all instances.

Return value

A structured array of instances.

2 calls to _media_gallery_controlled_instances()
media_gallery_install in ./media_gallery.install
Implements hook_install().
media_gallery_uninstall in ./media_gallery.install
Implements hook_uninstall().

File

./media_gallery.install, line 327
Install file for media_gallery. Includes field and instance definitions.

Code

function _media_gallery_controlled_instances($group = NULL) {
  $t = get_t();
  $node_instances = array(
    // The gallery description.
    'media_gallery_description' => array(
      'field_name' => 'media_gallery_description',
      'label' => $t('Description'),
      'widget' => array(
        'type' => 'text_textarea',
        'settings' => array(
          'rows' => 4,
        ),
      ),
      'settings' => array(
        'text_processing' => 1,
      ),
      'display' => array(
        'default' => array(
          'type' => 'text_default',
          'label' => 'hidden',
          'weight' => 0,
        ),
        'full' => array(
          'type' => 'text_default',
          'label' => 'hidden',
          'weight' => 0,
        ),
        'teaser' => array(
          'type' => 'hidden',
          'label' => 'hidden',
          'weight' => 0,
        ),
        'media_gallery_block' => array(
          'type' => 'hidden',
          'label' => 'hidden',
          'weight' => 0,
        ),
      ),
    ),
    'media_gallery_media' => array(
      'field_name' => 'media_gallery_media',
      'label' => $t('Gallery media'),
      'widget' => array(
        'type' => 'media_generic',
        'settings' => array(
          // Eventually other media types will be allowed.
          'allowed_types' => array(
            'audio' => 'audio',
            'image' => 'image',
            'video' => 'video',
          ),
          'allowed_schemes' => array(
            'public' => 'public',
          ),
        ),
      ),
      'display' => array(
        'default' => array(
          'type' => 'media_gallery',
          'settings' => array(
            'file_view_mode' => 'media_gallery_thumbnail',
          ),
          'label' => 'hidden',
          'weight' => 2,
        ),
        'full' => array(
          'type' => 'media_gallery',
          'settings' => array(
            'file_view_mode' => 'media_gallery_thumbnail',
          ),
          'label' => 'hidden',
          'weight' => 2,
        ),
        'teaser' => array(
          'type' => 'media_gallery',
          'settings' => array(
            'file_view_mode' => 'media_gallery_collection_thumbnail',
          ),
          'label' => 'hidden',
          'weight' => 2,
        ),
        'media_gallery_block' => array(
          'type' => 'media_gallery',
          'settings' => array(
            'file_view_mode' => 'media_gallery_block_thumbnail',
          ),
          'label' => 'hidden',
          'weight' => 2,
        ),
      ),
    ),
    // How to format the gallery (if links go to lightbox or node display).
    'media_gallery_format' => array(
      'field_name' => 'media_gallery_format',
      'label' => $t('Gallery format'),
      'required' => TRUE,
      'default_value' => array(
        array(
          'value' => 'lightbox',
        ),
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'full' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'teaser' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'media_gallery_block' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
      ),
      'widget' => array(
        'type' => 'options_buttons',
      ),
    ),
    // Whether to show a "Exclude title and description" checkbox.
    'media_gallery_lightbox_extras' => array(
      'field_name' => 'media_gallery_lightbox_extras',
      'label' => 'Lightbox title and description',
      'description' => $t('Show title and description'),
      'default_value' => array(
        array(
          'value' => 0,
        ),
      ),
      'widget' => array(
        'type' => 'options_onoff',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'full' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'teaser' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'media_gallery_block' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
      ),
    ),
    // How many columns to show.
    'media_gallery_columns' => array(
      'field_name' => 'media_gallery_columns',
      'label' => $t('Number of columns'),
      'default_value' => array(
        array(
          'value' => 4,
        ),
      ),
      'required' => TRUE,
      'widget' => array(
        'type' => 'options_select',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'full' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'teaser' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'media_gallery_block' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
      ),
    ),
    // How many rows to show.
    'media_gallery_rows' => array(
      'field_name' => 'media_gallery_rows',
      'label' => $t('Number of rows'),
      'default_value' => array(
        array(
          'value' => 3,
        ),
      ),
      'settings' => array(
        'min' => '1',
      ),
      'required' => TRUE,
      'widget' => array(
        'type' => 'number',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'full' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'teaser' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'media_gallery_block' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
      ),
    ),
    // Whether to show title/license on hover or below thumbnail.
    'media_gallery_image_info_where' => array(
      'field_name' => 'media_gallery_image_info_where',
      'label' => $t('Media information'),
      'required' => TRUE,
      'default_value' => array(
        array(
          'value' => 'hover',
        ),
      ),
      'widget' => array(
        'type' => 'options_select',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'full' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'teaser' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'media_gallery_block' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
      ),
    ),
    // Whether to show a "Download original image" checkbox.
    'media_gallery_allow_download' => array(
      'field_name' => 'media_gallery_allow_download',
      'label' => $t('Allow downloading of the original image'),
      'description' => $t('Display a "download original image" link'),
      'default_value' => array(
        array(
          'value' => 1,
        ),
      ),
      'widget' => array(
        'type' => 'options_onoff',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'full' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'teaser' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'media_gallery_block' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
      ),
    ),
    // Whether to expose a block for this gallery.
    'media_gallery_expose_block' => array(
      'field_name' => 'media_gallery_expose_block',
      'label' => $t('Create a block of most recently added media'),
      'default_value' => array(
        array(
          'value' => 0,
        ),
      ),
      'widget' => array(
        'type' => 'options_onoff',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'full' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'teaser' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'media_gallery_block' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
      ),
    ),
    // How many columns to show in the block.
    'media_gallery_block_columns' => array(
      'field_name' => 'media_gallery_block_columns',
      'label' => $t('Number of columns'),
      'default_value' => array(
        array(
          'value' => 2,
        ),
      ),
      'required' => TRUE,
      'widget' => array(
        'type' => 'options_select',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'full' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'teaser' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'media_gallery_block' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
      ),
    ),
    // How many rows to show in the block.
    'media_gallery_block_rows' => array(
      'field_name' => 'media_gallery_block_rows',
      'label' => $t('Number of rows'),
      'default_value' => array(
        array(
          'value' => 3,
        ),
      ),
      'required' => TRUE,
      'settings' => array(
        'min' => 1,
      ),
      'widget' => array(
        'type' => 'number',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'full' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'teaser' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'media_gallery_block' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
      ),
    ),
    // The 'collection' tag field on media gallery nodes.
    'media_gallery_collection' => array(
      'field_name' => 'media_gallery_collection',
      'label' => $t('Gallery collection'),
      'default_value' => array(
        array(
          'tid' => variable_get('media_gallery_default_collection_tid'),
        ),
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
        'teaser' => array(
          'type' => 'hidden',
          'label' => 'hidden',
        ),
      ),
    ),
  );
  foreach ($node_instances as &$instance) {
    $instance['entity_type'] = 'node';
    $instance['bundle'] = 'media_gallery';
  }
  unset($instance);
  $instances = array_intersect_key($node_instances, array_flip(array(
    'media_gallery_columns',
    'media_gallery_rows',
    'media_gallery_image_info_where',
  )));
  $instances['media_gallery_image_info_where']['label'] = $t('Gallery information');
  $instances['field_license'] = array(
    'field_name' => 'field_license',
    'label' => $t('Default license settings'),
    'required' => TRUE,
    'default_value' => array(
      array(
        'value' => 'nothing',
      ),
    ),
    'description' => $t('Choose a default <a href="http://creativecommons.org">@cc_link</a> license for all Gallery media. Later you can change the license for each piece of media.', array(
      '@cc_link' => 'Creative Commons',
    )),
    'weight' => 14,
    'display' => array(
      'default' => array(
        'type' => 'hidden',
        'label' => 'hidden',
      ),
      'teaser' => array(
        'type' => 'hidden',
        'label' => 'hidden',
      ),
    ),
  );
  foreach ($instances as $key => $instance) {

    // Since we are re-using fields which are defined for the node, we need to
    // remove any additional view modes which don't belong to avoid E_NOTICE errors.
    $instance['display'] = array_intersect_key($instance['display'], array_flip(array(
      'default',
      'full',
    )));
    $instance['entity_type'] = 'taxonomy_term';
    $instance['bundle'] = 'gallery_collections';
    $taxonomy_instances['taxo_term_' . $key] = $instance;
  }
  switch ($group) {
    case 'node':
      return $node_instances;
    case 'taxonomy_term':
      return $taxonomy_instances;
    default:
      return $node_instances + $taxonomy_instances;
  }
}