MailingListAccessControlHandler.php in Mailing List 8
File
src/MailingListAccessControlHandler.php
View source
<?php
namespace Drupal\mailing_list;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
class MailingListAccessControlHandler extends EntityAccessControlHandler {
public function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
if ($account
->hasPermission('administer mailing lists')) {
return AccessResult::allowed();
}
$list_id = $entity
->id();
if ($operation == 'view' || $operation == 'view label') {
$allowed_permissions = [
'administer mailing list subscriptions',
"subscribe to {$list_id} mailing list",
"view any {$list_id} mailing list subscriptions",
"update any {$list_id} mailing list subscriptions",
];
foreach ($allowed_permissions as $permission) {
if ($account
->hasPermission($permission)) {
return AccessResult::allowed();
}
}
}
return parent::checkAccess($entity, $operation, $account);
}
}