You are here

protected function MessageAccessControlHandler::checkAccess in Message UI 8

Link the activities to the permissions. checkAccess is called with the $operation as defined in the routing.yml file.

Overrides EntityAccessControlHandler::checkAccess

File

src/MessageAccessControlHandler.php, line 23

Class

MessageAccessControlHandler
Access controller for the comment entity.

Namespace

Drupal\message_ui

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {

  // Return early if we have bypass or create any template permissions.
  if ($account
    ->hasPermission('bypass message access control') || $account
    ->hasPermission($operation . ' any message template')) {
    return AccessResult::allowed()
      ->cachePerPermissions();
  }
  $params = [
    $entity,
    $operation,
    $account,
  ];

  /** @var \Drupal\Core\Access\AccessResult[] $results */
  $results = $this
    ->moduleHandler()
    ->invokeAll('message_message_ui_access_control', $params);
  foreach ($results as $result) {
    if ($result
      ->isNeutral()) {
      continue;
    }
    return $result;
  }
  return AccessResult::allowedIfHasPermission($account, $operation . ' ' . $entity
    ->bundle() . ' message')
    ->cachePerPermissions();
}