You are here

function _media_gallery_ensure_media_instances in Media Gallery 7.2

Same name and namespace in other branches
  1. 7 media_gallery.install \_media_gallery_ensure_media_instances()

Makes sure media entities have the fields media gallery requires.

2 calls to _media_gallery_ensure_media_instances()
media_gallery_install in ./media_gallery.install
Implements hook_install().
media_gallery_update_7200 in ./media_gallery.install
Converts old media_gallery_media field to media_gallery_file field.

File

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

Code

function _media_gallery_ensure_media_instances() {
  $t = get_t();
  $instances = _media_required_instances();
  foreach (file_type_get_enabled_types() as $bundle => $type) {
    foreach ($instances as $instance) {
      $instance_copy = $instance;
      $instance_copy += array(
        'entity_type' => 'file',
        'bundle' => $bundle,
      );
      $label = in_array($bundle, array(
        'image',
        'audio',
        'video',
      )) ? $bundle : 'file';
      if ($instance_copy['field_name'] == 'field_tags' && !isset($instance_copy['description'])) {
        $instance_copy['description'] = $t("Enter a comma-separated list of words to describe your {$label}.");
      }
      if ($instance_copy['field_name'] == 'field_license') {
        $instance_copy['label'] = $t("License settings for this {$label}");
        $instance_copy['description'] = $t('Select a <a href="http://creativecommons.org" target="_new">Creative Commons</a> license for others who use this ' . $label . '.');
      }
      _media_gallery_ensure_instance($instance_copy);
    }
  }
}