You are here

function metatag_update_7036 in Metatag 7

Update variables to indicate which entities should be supported.

File

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

Code

function metatag_update_7036() {
  foreach (entity_get_info() as $entity_type => $entity_info) {
    $variable_name = 'metatag_enable_' . $entity_type;

    // Configuration entities are skipped.
    if (isset($entity_info['configuration']) && $entity_info['configuration'] == TRUE) {
      continue;
    }
    elseif (empty($entity_info['view modes'])) {
      continue;
    }
    elseif (in_array($entity_type, array(
      'node',
      'taxonomy_term',
      'user',
    )) || !empty($entity_info['metatag']) || !empty($entity_info['metatags'])) {

      // Check if the entity type has been enabled or disabled previously; if
      // the variable equals a junk value then it was not previously set,
      // therefore we'll set a default.
      if (variable_get($variable_name, 'monkey') == 'monkey') {

        // By default these entity types are enabled.
        variable_set($variable_name, TRUE);

        // Check each entity bundle.
        if (!empty($entity_info['bundles'])) {
          foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
            $variable_name = 'metatag_enable_' . $entity_type . '__' . $bundle_name;

            // Check if the bundle has been enabled or disabled previously; if
            // the variable equals a junk value then it was not previously set,
            // therefore we'll set a default.
            if (variable_get($variable_name, 'monkey') == 'monkey') {
              if (!empty($bundle_info['metatag']) || !empty($bundle_info['metatags'])) {
                variable_set($variable_name, TRUE);
              }
              else {
                variable_set($variable_name, FALSE);
              }
            }
            else {

              // Do nothing.
            }
          }
        }
      }
      else {

        // Do nothing.
      }
    }
    else {
      variable_set($variable_name, FALSE);
    }
  }

  // Clear the caches.
  cache_clear_all('*', 'cache_metatag', TRUE);
  drupal_static_reset('metatag_config_load_with_defaults');
  drupal_static_reset('metatag_entity_supports_metatags');
  ctools_include('export');
  ctools_export_load_object_reset('metatag_config');
  drupal_set_message(t('The way that Metatag tracks which entity types are compatible has changed. Please review the <a href="@url">Settings page</a> to ensure that all of the entity types are enabled correctly.', array(
    '@url' => 'admin/config/search/metatags/settings',
  )));
}