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'
File
- src/
Controller/ HomeboxController.php, line 25
Class
- HomeboxController
- Class HomeboxController.
Namespace
Drupal\homebox\ControllerCode
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();
}