You are here

public function AccessControlHierarchyBase::checkEntityAccess in Workbench Access 8

Responds to request for node access.

Parameters

\Drupal\workbench_access\Entity\AccessSchemeInterface $scheme: Access scheme.

\Drupal\Core\Entity\EntityInterface $entity: The node being checked. In future this may handle other entity types.

string $op: The operation, e.g. update, delete.

\Drupal\Core\Session\AccountInterface $account: The user requesting access to the node.

Return value

\Drupal\Core\Access\AccessResultInterface An access result response. By design, this is either ignore or deny.

Overrides AccessControlHierarchyInterface::checkEntityAccess

See also

workbench_access_entity_access()

File

src/AccessControlHierarchyBase.php, line 191

Class

AccessControlHierarchyBase
Defines a base hierarchy class that others may extend.

Namespace

Drupal\workbench_access

Code

public function checkEntityAccess(AccessSchemeInterface $scheme, EntityInterface $entity, $op, AccountInterface $account) {
  if (!$this
    ->applies($entity
    ->getEntityTypeId(), $entity
    ->bundle())) {
    return AccessResult::neutral();
  }

  // Discover the field and check status.
  $entity_sections = $this
    ->getEntityValues($entity);

  // If no value is set on the entity, ignore.
  // @TODO: Is this the correct logic? It is helpful for new installs.
  $deny_on_empty = $this->config
    ->get('deny_on_empty');
  if (!$deny_on_empty && empty($entity_sections)) {
    return AccessResult::neutral();
  }
  $user_sections = $this->userSectionStorage
    ->getUserSections($scheme, $account);
  if (empty($user_sections)) {
    return AccessResult::forbidden();
  }

  // Check the tree status of the $entity against the $user.
  // Return neutral if in tree, forbidden if not.
  if (WorkbenchAccessManager::checkTree($scheme, $entity_sections, $user_sections)) {
    return AccessResult::neutral();
  }
  return AccessResult::forbidden();
}