You are here

function google_tag_realm_values in GoogleTagManager 7

Same name and namespace in other branches
  1. 7.2 google_tag.module \google_tag_realm_values()

Returns applicable realm name and key for the request.

Return value

array The realm name and key.

1 call to google_tag_realm_values()
google_tag_page_build in ./google_tag.module
Implements hook_page_build().

File

./google_tag.module, line 241
Provides primary Drupal hook implementations.

Code

function google_tag_realm_values() {
  $realm_name = $realm_key = '';
  if (module_exists('variable_realm') && module_exists('variable_store')) {

    // If realms exist, then the non-realm snippet files will not be loaded.
    // These are in the 'google_tag' directory beneath the site files directory.
    // If variable_realm module is later removed, then visit the module settings
    // page and update the settings.
    $realms = variable_realm_current();

    // Remove the global realm as this is always active.
    unset($realms['global']);
    if (empty($realms)) {
      $realm_name = 'global';
      $realm_key = 'default';
    }
    else {

      // The variable_realm module allows multiple realms to be 'active' on a
      // page request. The realms are ordered with 'greater' weight having
      // precedence. Select the last realm but allow other modules to override.
      $realm_name = key(array_reverse($realms));
      $realm_key = variable_realm_status($realm_name);
    }

    // Allow other modules to alter the realm name and key.
    $realm_values = array(
      'name' => $realm_name,
      'key' => $realm_key,
    );
    drupal_alter('google_tag_realm', $realm_values);
    $realm_name = $realm_values['name'];
    $realm_key = $realm_values['key'];
    $debug = variable_get('google_tag_debug_output', 0);
    $debug ? drupal_set_message(t('realm:key = @realm:@key', array(
      '@realm' => $realm_name,
      '@key' => $realm_key,
    ))) : '';
  }
  return array(
    $realm_name,
    $realm_key,
  );
}