public function MailingListManager::grantSessionAccess in Mailing List 8
Grants the current user access to a subscription for the current session.
Parameters
\Drupal\mailing_list\SubscriptionInterface\SubscriptionInterface $subscription: The subscription.
Overrides MailingListManagerInterface::grantSessionAccess
File
- src/
MailingListManager.php, line 55
Class
- MailingListManager
- Mailing list manager implementation.
Namespace
Drupal\mailing_listCode
public function grantSessionAccess(SubscriptionInterface $subscription) {
// We need user session even for anonymous users.
if ($this->currentUser
->isAnonymous() && !isset($_SESSION['session_started'])) {
$_SESSION['session_started'] = TRUE;
$this->sessionManager
->start();
}
if (!$this->sessionManager
->isStarted()) {
// Unable to start the session, may be called from CLI or no cookies
// allowed.
return;
}
// Add subscription to the session access permissions.
$collection = $this->userPrivateTempstore
->get('mailing_list');
if (!($grants = $collection
->get('grants'))) {
$grants = [];
}
$grants[$subscription
->uuid()] = REQUEST_TIME;
$collection
->set('grants', $grants);
}