You are here

public function HomeboxAddAccessCheck::access in Homebox 8

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

Parameters

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

\Drupal\homebox\Entity\HomeboxInterface $homebox: (optional) The homebox.

Return value

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

File

src/Access/HomeboxAddAccessCheck.php, line 46

Class

HomeboxAddAccessCheck
Determines access to for reference add pages.

Namespace

Drupal\homebox\Access

Code

public function access(AccountInterface $account, HomeboxInterface $homebox = NULL) {
  $access_control_handler = $this->entityManager
    ->getAccessControlHandler('homebox_layout');

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

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