Same name and namespace in other branches
  1. 5.0.x advagg.module \advagg_enabled() 1 commentaire
  2. 7.x-2.x advagg.module \advagg_enabled() 1 commentaire
  3. 8.x-2.x advagg.module \advagg_enabled() 1 commentaire
  4. 8.x-3.x advagg.module \advagg_enabled() 1 commentaire
  5. 8.x-4.x advagg.module \advagg_enabled() 1 commentaire

Function used to check if AdvAgg is enabled.

Most often will be the value of advagg.settings.enabled, but may also be affected by maintenance mode, debug cookies and or $_GET variables.

Return value

bool Whether AdvAgg functionality should be used.

4 calls to advagg_enabled()
advagg_css_alter dans ./advagg.module
Implements hook_css_alter().
advagg_js_alter dans ./advagg.module
Implements hook_js_alter().
advagg_mod_css_alter dans advagg_mod/advagg_mod.module
Implements hook_css_alter().
advagg_mod_js_alter dans advagg_mod/advagg_mod.module
Implements hook_js_alter().
1 string reference to 'advagg_enabled'
d7_advagg_settings.yml dans migrations/d7_advagg_settings.yml
migrations/d7_advagg_settings.yml

Fichier

./advagg.module, line 153

Code

function advagg_enabled() {
    $init =& drupal_static(__FUNCTION__);
    $messenger = \Drupal::messenger();
    if (!empty($init)) {
        return $init['advagg'];
    }
    $advagg_config = \Drupal::config('advagg.settings');
    $user = \Drupal::currentUser();
    $init['advagg'] = $advagg_config->get('enabled');
    // Disable AdvAgg if maintenance mode is defined.
    if (defined('MAINTENANCE_MODE')) {
        $init['advagg'] = FALSE;
        return FALSE;
    }
    // Allow for AdvAgg to be enabled/disabled per request.
    if (isset($_GET['advagg']) && $user->hasPermission('bypass advanced aggregation')) {
        if ($_GET['advagg'] == 1) {
            $init['advagg'] = TRUE;
        }
        else {
            $init['advagg'] = FALSE;
        }
    }
    // Do not use AdvAgg if the disable cookie is set.
    $cookie_name = 'AdvAggDisabled';
    $key = Crypt::hashBase64(\Drupal::service('private_key')->get());
    if (!empty($_COOKIE[$cookie_name]) && $_COOKIE[$cookie_name] == $key) {
        $init['advagg'] = FALSE;
        // Let the user know that the AdvAgg bypass cookie is currently set.
        static $msg_set;
        if (!isset($msg_set) && $advagg_config->get('show_bypass_cookie_message')) {
            $msg_set = TRUE;
            if (\Drupal::currentUser()->hasPermission('administer site configuration')) {
                $messenger->addMessage(t('The AdvAgg bypass cookie is currently enabled. Turn it off by going to the <a href="@advagg_operations">AdvAgg Operations</a> page and clicking the <em>Toggle the "aggregation bypass cookie" for this browser</em> button.', [
                    '@advagg_operations' => Url::fromRoute('advagg.operations', [], [
                        'fragment' => 'edit-bypass',
                    ])->toString(),
                ]));
            }
            else {
                $messenger->addMessage(t('The AdvAgg bypass cookie is currently enabled. Turn it off by <a href="@login">logging in</a> with a user with the "administer site configuration" permissions and going to the <a herf="@advagg_operations">AdvAgg Operations page</a> and clicking the <em>Toggle the "aggregation bypass cookie" for this browser</em> button.', [
                    '@login' => '/user/login',
                    '@advagg_operations' => Url::fromRoute('advagg.operations')->toString(),
                ]));
            }
        }
    }
    return $init['advagg'];
}