You are here

media_gallery_extra.install in Media Gallery Extra 7

Install, update and uninstall functions for the media gallery extra module.

File

media_gallery_extra.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the media gallery extra module.
 */

/**
 * Implements hook_install().
 */
function media_gallery_extra_install() {

  // Set module weight to a value higher than media_gallery.
  media_gallery_extra_update_weight();
}

/**
 * Implements hook_uninstall().
 */
function media_gallery_extra_uninstall() {

  // Remove variables.
  variable_del('media_gallery_extra_root_directory');
  variable_del('media_gallery_extra_license_enable');
  variable_del('media_gallery_extra_block_enable');
  variable_del('media_gallery_extra_block_access');
}

/**
 * Helper function to set module weight to a value higher than media_gallery.
 */
function media_gallery_extra_update_weight($module = 'media_gallery_extra') {
  $weight = db_query("SELECT weight FROM {system} WHERE type = 'module' AND name = 'media_gallery'")
    ->fetchField();
  db_update('system')
    ->fields(array(
    'weight' => $weight + 1,
  ))
    ->condition('type', 'module')
    ->condition('name', $module)
    ->execute();
}

/**
 * Helper function to create new fields.
 */
function media_gallery_extra_create_fields($fields, $update = FALSE) {
  foreach ($fields as $field) {
    $existing_field = field_read_field($field['field_name'], array(
      'include_inactive' => TRUE,
    ));
    if (empty($existing_field)) {
      field_create_field($field);
    }
    else {
      if ($update) {
        field_update_field($field);
      }
    }
  }
}

/**
 * Helper function to create new instance fields.
 */
function media_gallery_extra_create_instances($field_instances, $entity_type = 'node', $bundle = 'media_gallery', $update = FALSE) {
  foreach ($field_instances as $instance) {
    $instance['entity_type'] = $entity_type;
    $instance['bundle'] = $bundle;
    $existing_instance = field_info_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']);
    if (empty($existing_instance)) {
      field_create_instance($instance);
    }
    else {
      if ($update) {
        field_update_instance($instance);
      }
    }
  }
}

Functions

Namesort descending Description
media_gallery_extra_create_fields Helper function to create new fields.
media_gallery_extra_create_instances Helper function to create new instance fields.
media_gallery_extra_install Implements hook_install().
media_gallery_extra_uninstall Implements hook_uninstall().
media_gallery_extra_update_weight Helper function to set module weight to a value higher than media_gallery.