class ComposeAccessCheck in Courier 8
Same name and namespace in other branches
- 2.x courier_message_composer/src/Access/ComposeAccessCheck.php \Drupal\courier_message_composer\Access\ComposeAccessCheck
Checks if user can send to a channel.
Hierarchy
- class \Drupal\courier_message_composer\Access\ComposeAccessCheck implements AccessInterface
Expanded class hierarchy of ComposeAccessCheck
1 string reference to 'ComposeAccessCheck'
- courier_message_composer.services.yml in courier_message_composer/
courier_message_composer.services.yml - courier_message_composer/courier_message_composer.services.yml
1 service uses ComposeAccessCheck
File
- courier_message_composer/
src/ Access/ ComposeAccessCheck.php, line 15
Namespace
Drupal\courier_message_composer\AccessView source
class ComposeAccessCheck implements AccessInterface {
/**
* The identity channel manager.
*
* @var \Drupal\courier\Service\IdentityChannelManagerInterface
*/
protected $identityChannelManager;
/**
* Constructs a ComposeAccessCheck object.
*
* @param \Drupal\courier\Service\IdentityChannelManagerInterface $identity_channel_manager
* The identity channel manager.
*/
public function __construct(IdentityChannelManagerInterface $identity_channel_manager) {
$this->identityChannelManager = $identity_channel_manager;
}
/**
* Checks if user can send to a channel.
*/
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
$requirement = $route
->getRequirement('_courier_compose');
$channels_all = $this->identityChannelManager
->getChannels();
$channels = [];
if ($requirement == '*') {
// Check if user can send to *any* channel.
$channels = array_keys($channels_all);
}
elseif ($courier_channel = $route_match
->getParameter('courier_channel')) {
$channels = array_key_exists($courier_channel
->id(), $channels_all) ? [
$courier_channel
->id(),
] : [];
}
foreach ($channels as $channel) {
foreach ($channels_all[$channel] as $identity) {
if ($account
->hasPermission("courier_message_composer compose {$channel} to {$identity}")) {
return AccessResult::allowed()
->cachePerPermissions();
}
}
}
return AccessResult::forbidden()
->cachePerPermissions();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ComposeAccessCheck:: |
protected | property | The identity channel manager. | |
ComposeAccessCheck:: |
public | function | Checks if user can send to a channel. | |
ComposeAccessCheck:: |
public | function | Constructs a ComposeAccessCheck object. |