protected function AgreementHandler::agreeAnonymously in Agreement 3.0.x
Same name and namespace in other branches
- 8.2 src/AgreementHandler.php \Drupal\agreement\AgreementHandler::agreeAnonymously()
Accept agreement for an anonymous user.
Parameters
\Drupal\Core\Session\AccountProxyInterface $account: The user account to agree.
\Drupal\agreement\Entity\Agreement $agreement: The agreement that the user is agreeing to.
int $agreed: An optional integer to set the agreement status to. Defaults to 1.
Return value
\Symfony\Component\HttpFoundation\Cookie A cookie to retain the user's acceptance of the agreement.
1 call to AgreementHandler::agreeAnonymously()
- AgreementHandler::agree in src/
AgreementHandler.php - Accept the agreement for an user account.
File
- src/
AgreementHandler.php, line 219
Class
- AgreementHandler
- Agreement handler provides methods for looking up agreements.
Namespace
Drupal\agreementCode
protected function agreeAnonymously(AccountProxyInterface $account, Agreement $agreement, $agreed) {
$agreementType = $agreement
->id();
$cookieName = static::ANON_AGREEMENT_COOKIE_PREFIX . $agreementType;
$expire = 0;
if ($agreement
->getSettings()['frequency'] == 365) {
$expire = new \DateTime('+1 year');
}
elseif ($agreement
->agreeOnce()) {
$expire = new \DateTime('+10 years');
}
return new Cookie($cookieName, $agreed, $expire, '/', NULL, NULL, 'lax');
}