You are here

public function LogAddAccessCheck::access in Log entity 8

Checks access to the log add page for the log type.

Parameters

\Drupal\Core\Session\AccountInterface $account: The currently logged in account.

\Drupal\log\LogTypeInterface $log_type: (optional) The log type. If not specified, access is allowed if there exists at least one log type for which the user may create a log.

Return value

string A \Drupal\Core\Access\AccessInterface constant value.

File

src/Access/LogAddAccessCheck.php, line 52
Contains \Drupal\log\Access\LogAddAccessCheck.

Class

LogAddAccessCheck
Determines access to for log add pages.

Namespace

Drupal\log\Access

Code

public function access(AccountInterface $account, LogTypeInterface $log_type = NULL) {
  $access_control_handler = $this->entityManager
    ->getAccessControlHandler('log');

  // If checking whether a log of a particular type may be created.
  if ($account
    ->hasPermission('administer log types')) {
    return AccessResult::allowed()
      ->cachePerPermissions();
  }
  if ($log_type) {
    return $access_control_handler
      ->createAccess($log_type
      ->id(), $account, [], TRUE);
  }

  // If checking whether a log of any type may be created.
  foreach ($this->entityManager
    ->getStorage('log_type')
    ->loadMultiple() as $log_type) {
    if (($access = $access_control_handler
      ->createAccess($log_type
      ->id(), $account, [], TRUE)) && $access
      ->isAllowed()) {
      return $access;
    }
  }

  // No opinion.
  return AccessResult::neutral();
}