You are here

function media_gallery_requirements in Media Gallery 7

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

Implements hook_requirements().

File

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

Code

function media_gallery_requirements() {
  $requirements = array();

  // If this module is part of an install profile, its requirements will be
  // checked before the field system is available. The rest of this function is
  // unneeded anyway in that case, so bail out here to avoid fatal errors.
  if (!module_exists('field')) {
    return $requirements;
  }
  $t = get_t();
  $required_fields = _media_gallery_controlled_fields();

  // In addition to the fields we control, we also need the standard field_tags
  // that most sites will have gotten from their install profile.
  $required_fields['field_tags'] = array(
    'type' => 'taxonomy_term_reference',
  );
  foreach ($required_fields as $field_name => $field_definition) {
    $field = field_info_field($field_name);

    // If the field doesn't exist, we will create it on install.
    if (!$field) {
      continue;
    }

    // Between Media Gallery beta2 and beta3, field definitions were changed
    // from list_number to list_float, to keep up with Drupal core changes.
    // list_update_7001() handles the updating of existing fields, but
    // update.php checks all requirements prior to running any update function.
    if ($field['type'] == 'list_number' && $field_definition['type'] == 'list_float') {
      continue;
    }
    if ($field['type'] != $field_definition['type']) {
      $requirements['existing_field_' . $field_name] = array(
        'description' => $t("%field_name already exists and is not of type %type. Installation cannot continue. Please remove this field or change its type.", array(
          '%field_name' => $field_name,
          '%type' => $field_definition['type'],
        )),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $requirements;
}