function media_gallery_install in Media Gallery 7.2
Same name and namespace in other branches
- 7 media_gallery.install \media_gallery_install()
Implements hook_install().
File
- ./
media_gallery.install, line 20 - Install file for media_gallery. Includes field and instance definitions.
Code
function media_gallery_install() {
// Adjust bundle settings for the media gallery content type.
$bundle_settings = field_bundle_settings('node', 'media_gallery');
// Enable the gallery block and full view modes.
$bundle_settings['view_modes']['media_gallery_block']['custom_settings'] = TRUE;
$bundle_settings['view_modes']['full']['custom_settings'] = TRUE;
// Adjust the "Add media link" extra field so that it only displays on the
// full node view, with the correct weight relative to the other fields. In
// particular, we put it directly after the 'media_gallery_description'
// field; see _media_gallery_controlled_instances().
$bundle_settings['extra_fields']['display']['add_media_link']['full']['weight'] = 1;
$bundle_settings['extra_fields']['display']['add_media_link']['full']['visible'] = TRUE;
$bundle_settings['extra_fields']['display']['add_media_link']['default']['visible'] = FALSE;
$bundle_settings['extra_fields']['display']['add_media_link']['teaser']['visible'] = FALSE;
$bundle_settings['extra_fields']['display']['add_media_link']['media_gallery_block']['visible'] = FALSE;
// _field_extra_fields_pre_render() requires an explicit 'weight' value for
// all extra field settings stored in the database.
foreach ($bundle_settings['extra_fields']['display']['add_media_link'] as $name => $view_mode) {
$bundle_settings['extra_fields']['display']['add_media_link'][$name]['weight'] = 1;
}
// Save the new bundle settings.
field_bundle_settings('node', 'media_gallery', $bundle_settings);
// Enable custom display settings for gallery context view modes for file
// types that can be in a gallery.
foreach (array(
'audio',
'image',
'video',
) as $bundle) {
$bundle_settings = field_bundle_settings('file', $bundle);
foreach (media_gallery_file_view_modes() as $view_mode => $label) {
$bundle_settings['view_modes'][$view_mode]['custom_settings'] = TRUE;
}
field_bundle_settings('file', $bundle, $bundle_settings);
}
// Clear caches so that our implementation of hook_image_default_styles() is
// correctly used when all the fields created below need it to be.
// @todo There should obviously be a cleaner way to do this.
cache_clear_all('*', 'cache', TRUE);
drupal_static_reset('image_styles');
drupal_static_reset('image_effects');
if (module_exists('styles') && function_exists('styles_style_flush')) {
styles_style_flush();
}
// Add the taxonomy vocabulary for media gallery collections.
$vocabulary = media_gallery_create_taxonomy_vocab();
// Make sure the standard 'field_tags' field exists.
_media_gallery_ensure_field_tags();
// Create fields (but not instances yet) for media_gallery nodes and
// for the gallery collection vocabulary.
foreach (_media_gallery_controlled_fields() as $field) {
_media_gallery_ensure_field($field);
}
// Attach fields to gallery_collection taxonomy terms.
foreach (_media_gallery_controlled_instances('taxonomy_term') as $instance) {
_media_gallery_ensure_instance($instance);
}
// Now that the gallery_collection vocabulary exists and has fields attached,
// create an "All galleries" term for galleries to belong to by default.
media_gallery_create_taxonomy_term($vocabulary);
// Attach fields to the media gallery node type (including a term reference
// for the default collection).
foreach (_media_gallery_controlled_instances('node') as $instance) {
_media_gallery_ensure_instance($instance);
}
// Make sure all media bundles have the instances we expect.
_media_gallery_ensure_media_instances();
// Set variables for the media gallery node type.
variable_set('node_submitted_media_gallery', FALSE);
variable_set('node_options_media_gallery', array(
'status',
));
variable_set('comment_media_gallery', 0);
}