class ReorderChildrenAccess in Entity Reference Hierarchy 8.2
Same name and namespace in other branches
- 3.x src/Routing/ReorderChildrenAccess.php \Drupal\entity_hierarchy\Routing\ReorderChildrenAccess
Defines a class for limiting the children form to entities with hierarchies.
Hierarchy
- class \Drupal\entity_hierarchy\Routing\ReorderChildrenAccess implements AccessCheckInterface
Expanded class hierarchy of ReorderChildrenAccess
1 string reference to 'ReorderChildrenAccess'
1 service uses ReorderChildrenAccess
File
- src/
Routing/ ReorderChildrenAccess.php, line 16
Namespace
Drupal\entity_hierarchy\RoutingView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ReorderChildrenAccess:: |
protected | property | Parent candidate service. | |
ReorderChildrenAccess:: |
protected | property | Route match. | |
ReorderChildrenAccess:: |
public | function | Checks access. | |
ReorderChildrenAccess:: |
public | function |
Declares whether the access check applies to a specific route or not. Overrides AccessCheckInterface:: |
|
ReorderChildrenAccess:: |
public | function | Constructs a new ReorderChildrenAccess object. |