Same name in other branches
- 5.0.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::toggleBypassCookie()
- 6.0.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::toggleBypassCookie()
- 8.x-2.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::toggleBypassCookie()
- 8.x-3.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::toggleBypassCookie()
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\FormCode
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();
}