You are here

function metatag_install in Metatag 7

Implements hook_install().

File

./metatag.install, line 355
Install, update, and uninstall functions for the metatag module.

Code

function metatag_install() {
  drupal_set_message(t("Thank you for installing the Metatag module. It is recommended to read the module's <a href=\"!url\" title=\"Read the Metatag module's documentation\">README.txt</a> file as there are some known issues that may affect this site.", array(
    '!url' => url(drupal_get_path('module', 'metatag') . '/README.txt'),
  )));

  // Always enable the node, taxonomy term and user entities.
  foreach (array(
    'node',
    'taxonomy_term',
    'user',
  ) as $entity_type) {

    // Enable the main entity type.
    $variable_name = 'metatag_enable_' . $entity_type;
    variable_set($variable_name, TRUE);

    // Update each entity bundle too.
    $entity_info = entity_get_info($entity_type);
    if (!empty($entity_info['bundles'])) {
      foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
        $variable_name = 'metatag_enable_' . $entity_type . '__' . $bundle_name;
        variable_set($variable_name, TRUE);
      }
    }
  }

  // Possibly enable other entities, if they're specifically requested.
  foreach (entity_get_info() as $entity_type => $entity_info) {

    // Skip the three entity types that were already enabled.
    if (in_array($entity_type, array(
      'node',
      'taxonomy_term',
      'user',
    ))) {
      continue;
    }
    $variable_name = 'metatag_enable_' . $entity_type;

    // Configuration entities are skipped.
    if (isset($entity_info['configuration']) && $entity_info['configuration'] == TRUE) {
      continue;
    }

    // Entities must have bundles.
    if (empty($entity_info['bundles'])) {
      continue;
    }
    elseif (empty($entity_info['fieldable'])) {
      continue;
    }

    // Ignore some view modes that are automatically added by certain modules.
    unset($entity_info['view modes']['ical']);
    unset($entity_info['view modes']['diff_standard']);
    unset($entity_info['view modes']['token']);

    // Entities without view modes are skipped.
    if (empty($entity_info['view modes'])) {
      continue;
    }

    // At this point, disable the entity by default.
    $entity_enabled = FALSE;

    // Anything that was specifically enabled via hook_entity_info() from older
    // versions will be enabled if not configured already.
    if (!empty($entity_info['metatag']) || !empty($entity_info['metatags'])) {
      $entity_enabled = variable_get($variable_name, 'monkey');
      if ($entity_enabled === 'monkey') {
        $entity_enabled = TRUE;
      }
    }
    variable_set($variable_name, $entity_enabled);

    // Loop through the bundles, but only if the entity is enabled.
    if ($entity_enabled) {
      foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
        $variable_name = 'metatag_enable_' . $entity_type . '__' . $bundle_name;

        // If it wasn't specifically disabled before, enable it.
        $bundle_enabled = variable_get($variable_name, 'monkey');
        if ($bundle_name != FALSE) {
          variable_set($variable_name, TRUE);
        }
      }
    }
  }
  drupal_set_message(t('It may be worth verifying on the <a href="@url">Settings page</a> which types of content on the site should allow meta tags.', array(
    '@url' => url('admin/config/search/metatags/settings'),
  )));
}