You are here

public function ThemeSwitcherAccessControlHandler::checkAccess in Theme Switcher Rules 8

Performs access checks.

This method is supposed to be overwritten by extending classes that do their own custom access checking.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check access.

string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.

\Drupal\Core\Session\AccountInterface $account: The user for which to check access.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

Overrides EntityAccessControlHandler::checkAccess

File

src/Access/ThemeSwitcherAccessControlHandler.php, line 18

Class

ThemeSwitcherAccessControlHandler
Defines the access controller for the theme_switcher_rule entity type.

Namespace

Drupal\theme_switcher\Access

Code

public function checkAccess(EntityInterface $entity, $operation, AccountInterface $account = NULL) {
  $account = $this
    ->prepareUser($account);

  // Check the global permission.
  if ($account
    ->hasPermission('administer theme switcher rules')) {
    return AccessResult::allowed();
  }
  if ($operation == 'view' && $account
    ->hasPermission('view theme switcher rules')) {
    return AccessResult::allowed();
  }
  elseif ($operation == 'update' && $account
    ->hasPermission('edit theme switcher rules')) {
    return AccessResult::allowed();
  }
  elseif ($operation == 'delete' && $account
    ->hasPermission('delete theme switcher rules')) {
    return AccessResult::allowed();
  }
  return AccessResult::forbidden();
}