You are here

public function HomeboxController::access in Homebox 8

Check access to Homebox entity.

Parameters

\Drupal\homebox\Entity\HomeboxInterface $homebox: Homebox entity.

Return value

\Drupal\Core\Access\AccessResultAllowed|\Drupal\Core\Access\AccessResultForbidden Access result.

1 string reference to 'HomeboxController::access'
homebox.routing.yml in ./homebox.routing.yml
homebox.routing.yml

File

src/Controller/HomeboxController.php, line 25

Class

HomeboxController
Class HomeboxController.

Namespace

Drupal\homebox\Controller

Code

public function access(HomeboxInterface $homebox) {
  $user = $this
    ->currentUser();
  if ($user
    ->hasPermission('administer homebox')) {
    return AccessResult::allowed();
  }
  if ($homebox
    ->getOptions()['status']) {
    $user_roles = $user
      ->getRoles();
    $allowed_roles = array_values($homebox
      ->getRoles());
    foreach ($user_roles as $delta => $role) {
      if (in_array($role, $allowed_roles)) {
        $access = AccessResult::allowed();
        return $access;
      }
    }
  }
  return AccessResult::forbidden();
}