Same name and namespace in other branches
  1. 5.0.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::toggleBypassCookie() 1 commentaire
  2. 8.x-2.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::toggleBypassCookie() 1 commentaire
  3. 8.x-3.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::toggleBypassCookie() 1 commentaire
  4. 8.x-4.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::toggleBypassCookie() 1 commentaire

Set or remove the AdvAggDisabled cookie.

Paramètres

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Fichier

src/Form/OperationsForm.php, line 272

Classe

OperationsForm
Configure advagg settings for this site.

Namespace

Drupal\advagg\Form

Code

public function toggleBypassCookie(array &$form, FormStateInterface $form_state) {
    $cookie_name = 'AdvAggDisabled';
    $key = Crypt::hashBase64($this->privateKey
        ->get());
    // If the cookie does exist then remove it.
    if (!empty($_COOKIE[$cookie_name]) && $_COOKIE[$cookie_name] == $key) {
        setcookie($cookie_name, '', -1, $GLOBALS['base_path'], '.' . $_SERVER['HTTP_HOST']);
        unset($_COOKIE[$cookie_name]);
        $this->messenger()
            ->addMessage($this->t('AdvAgg Bypass Cookie Removed.'));
    }
    else {
        setcookie($cookie_name, $key, $this->time
            ->getRequestTime() + $form_state->getValue('timespan'), $GLOBALS['base_path'], '.' . $_SERVER['HTTP_HOST']);
        $_COOKIE[$cookie_name] = $key;
        $this->messenger()
            ->addMessage($this->t('AdvAgg Bypass Cookie Set for %time.', [
            '%time' => $this->dateFormatter
                ->formatInterval($form_state->getValue('timespan')),
        ]));
    }
    $this->clearAggregates();
}