You are here

class ReorderChildrenAccess in Entity Reference Hierarchy 8.2

Same name and namespace in other branches
  1. 3.x src/Routing/ReorderChildrenAccess.php \Drupal\entity_hierarchy\Routing\ReorderChildrenAccess

Defines a class for limiting the children form to entities with hierarchies.

Hierarchy

Expanded class hierarchy of ReorderChildrenAccess

1 string reference to 'ReorderChildrenAccess'
entity_hierarchy.services.yml in ./entity_hierarchy.services.yml
entity_hierarchy.services.yml
1 service uses ReorderChildrenAccess
access_check.entity_hierarchy.has_fields in ./entity_hierarchy.services.yml
Drupal\entity_hierarchy\Routing\ReorderChildrenAccess

File

src/Routing/ReorderChildrenAccess.php, line 16

Namespace

Drupal\entity_hierarchy\Routing
View source
class ReorderChildrenAccess implements AccessCheckInterface {

  /**
   * Route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * Parent candidate service.
   *
   * @var \Drupal\entity_hierarchy\Information\ParentCandidateInterface
   */
  protected $parentCandidate;

  /**
   * Constructs a new ReorderChildrenAccess object.
   *
   * @param \Drupal\entity_hierarchy\Information\ParentCandidateInterface $parentCandidate
   *   Parent candidate service.
   * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
   *   Route match.
   */
  public function __construct(ParentCandidateInterface $parentCandidate, RouteMatchInterface $routeMatch) {
    $this->routeMatch = $routeMatch;
    $this->parentCandidate = $parentCandidate;
  }

  /**
   * {@inheritdoc}
   */
  public function applies(Route $route) {
    return $route
      ->hasRequirement(EntityHierarchyRouteProvider::ENTITY_HIERARCHY_HAS_FIELD);
  }

  /**
   * Checks access.
   *
   * @param \Symfony\Component\Routing\Route $route
   *   Route being access checked.
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The request object.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access(Route $route, Request $request = NULL, AccountInterface $account = NULL) {
    $entity_type = $route
      ->getOption(EntityHierarchyRouteProvider::ENTITY_HIERARCHY_ENTITY_TYPE);
    $entity = $this->routeMatch
      ->getParameter($entity_type);
    if ($entity && $this->parentCandidate
      ->getCandidateFields($entity)) {
      return AccessResult::allowed()
        ->setCacheMaxAge(0);
    }
    return AccessResult::forbidden();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ReorderChildrenAccess::$parentCandidate protected property Parent candidate service.
ReorderChildrenAccess::$routeMatch protected property Route match.
ReorderChildrenAccess::access public function Checks access.
ReorderChildrenAccess::applies public function Declares whether the access check applies to a specific route or not. Overrides AccessCheckInterface::applies
ReorderChildrenAccess::__construct public function Constructs a new ReorderChildrenAccess object.