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-3.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::toggleBypassCookie()
- 8.x-4.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 443
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]);
drupal_set_message($this->t('AdvAgg Bypass Cookie Removed.'));
}
else {
setcookie($cookie_name, $key, REQUEST_TIME + $form_state->getValue('timespan'), $GLOBALS['base_path'], '.' . $_SERVER['HTTP_HOST']);
$_COOKIE[$cookie_name] = $key;
drupal_set_message($this->t('AdvAgg Bypass Cookie Set for %time.', [
'%time' => $this->dateFormatter
->formatInterval($form_state->getValue('timespan')),
]));
}
}