class MailingListManager in Mailing List 8
Mailing list manager implementation.
Hierarchy
- class \Drupal\mailing_list\MailingListManager implements MailingListManagerInterface
Expanded class hierarchy of MailingListManager
1 string reference to 'MailingListManager'
1 service uses MailingListManager
File
- src/
MailingListManager.php, line 13
Namespace
Drupal\mailing_listView source
class MailingListManager implements MailingListManagerInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The session manager.
*
* @var \Drupal\Core\Session\SessionManagerInterface
*/
protected $sessionManager;
/**
* The user private temp store factory.
*
* @var \Drupal\user\PrivateTempStoreFactory
*/
protected $userPrivateTempstore;
/**
* Create a new mailing list manager instance.
*
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Session\SessionManagerInterface $session_manager
* The session manager.
* @param \Drupal\user\PrivateTempStoreFactory $user_private_tempstore
* The user temp store.
*/
public function __construct(AccountInterface $current_user, SessionManagerInterface $session_manager, PrivateTempStoreFactory $user_private_tempstore) {
$this->currentUser = $current_user;
$this->sessionManager = $session_manager;
$this->userPrivateTempstore = $user_private_tempstore;
}
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
public function revokeSessionAccess(SubscriptionInterface $subscription) {
if ($this
->hasSessionAccess($subscription)) {
$collection = $this->userPrivateTempstore
->get('mailing_list');
$grants = $collection
->get('grants');
unset($grants[$subscription
->uuid()]);
$collection
->set('grants', $grants);
}
}
/**
* {@inheritdoc}
*/
public function hasSessionAccess(SubscriptionInterface $subscription) {
return $this->sessionManager
->isStarted() && ($grants = $this->userPrivateTempstore
->get('mailing_list')
->get('grants')) && isset($grants[$subscription
->uuid()]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MailingListManager:: |
protected | property | The current user. | |
MailingListManager:: |
protected | property | The session manager. | |
MailingListManager:: |
protected | property | The user private temp store factory. | |
MailingListManager:: |
public | function |
Grants the current user access to a subscription for the current session. Overrides MailingListManagerInterface:: |
|
MailingListManager:: |
public | function |
Checks if the current user has session access to a given subscription. Overrides MailingListManagerInterface:: |
|
MailingListManager:: |
public | function |
Revoke any session access to a subscription to the current user. Overrides MailingListManagerInterface:: |
|
MailingListManager:: |
public | function | Create a new mailing list manager instance. |