You are here

protected function ThunderTermAccessControlHandler::checkAccess in Thunder 8.4

Same name and namespace in other branches
  1. 8.5 modules/thunder_taxonomy/src/ThunderTermAccessControlHandler.php \Drupal\thunder_taxonomy\ThunderTermAccessControlHandler::checkAccess()
  2. 8.2 modules/thunder_taxonomy/src/ThunderTermAccessControlHandler.php \Drupal\thunder_taxonomy\ThunderTermAccessControlHandler::checkAccess()
  3. 8.3 modules/thunder_taxonomy/src/ThunderTermAccessControlHandler.php \Drupal\thunder_taxonomy\ThunderTermAccessControlHandler::checkAccess()
  4. 6.2.x modules/thunder_taxonomy/src/ThunderTermAccessControlHandler.php \Drupal\thunder_taxonomy\ThunderTermAccessControlHandler::checkAccess()
  5. 6.0.x modules/thunder_taxonomy/src/ThunderTermAccessControlHandler.php \Drupal\thunder_taxonomy\ThunderTermAccessControlHandler::checkAccess()
  6. 6.1.x modules/thunder_taxonomy/src/ThunderTermAccessControlHandler.php \Drupal\thunder_taxonomy\ThunderTermAccessControlHandler::checkAccess()

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 TermAccessControlHandler::checkAccess

File

modules/thunder_taxonomy/src/ThunderTermAccessControlHandler.php, line 20

Class

ThunderTermAccessControlHandler
Defines the access control handler for the taxonomy term entity type.

Namespace

Drupal\thunder_taxonomy

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
  switch ($operation) {
    case 'view':

      // Check for status and set 'published' or 'unpublished'.
      $status = $entity->status->value ? 'published' : 'unpublished';
      return AccessResult::allowedIf($account
        ->hasPermission('access content') && $account
        ->hasPermission('view ' . $status . ' terms in ' . $entity
        ->bundle()));
    default:
      return parent::checkAccess($entity, $operation, $account);
  }
}