Loading entity_hierarchy.services.yml +1 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ services: arguments: ['@entity_field.manager', '@entity_type.bundle.info'] access_check.entity_hierarchy.has_fields: class: Drupal\entity_hierarchy\Routing\ReorderChildrenAccess arguments: ['@entity_hierarchy.information.parent_candidate', '@current_route_match'] arguments: ['@entity_hierarchy.information.parent_candidate', '@current_route_match', '@entity_type.manager'] tags: - { name: access_check } entity_hierarchy.entity_tree_node_mapper: Loading src/Routing/ReorderChildrenAccess.php +26 −1 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ namespace Drupal\entity_hierarchy\Routing; use Drupal\Core\Access\AccessCheckInterface; use Drupal\Core\Access\AccessResult; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\entity_hierarchy\Information\ParentCandidateInterface; Loading @@ -29,6 +31,13 @@ class ReorderChildrenAccess implements AccessCheckInterface { */ protected $parentCandidate; /** * Entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** * Constructs a new ReorderChildrenAccess object. * Loading @@ -37,9 +46,10 @@ class ReorderChildrenAccess implements AccessCheckInterface { * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch * Route match. */ public function __construct(ParentCandidateInterface $parentCandidate, RouteMatchInterface $routeMatch) { public function __construct(ParentCandidateInterface $parentCandidate, RouteMatchInterface $routeMatch, EntityTypeManagerInterface $entityTypeManager) { $this->routeMatch = $routeMatch; $this->parentCandidate = $parentCandidate; $this->entityTypeManager = $entityTypeManager; } /** Loading @@ -65,6 +75,21 @@ class ReorderChildrenAccess implements AccessCheckInterface { 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 a user has configured a local task with views at e.g. // node/{node}/media then the {node} object isn't upcast. // @todo revisit this when // https://www.drupal.org/project/drupal/issues/2528166 is resolved if (!$entity instanceof EntityInterface) { $storage = $this->entityTypeManager->getStorage($entity_type); $entity = $storage->load($entity); if (!$entity) { // At this point we can't proceed so we err on the side of caution and // deny access to the tab. return AccessResult::forbidden(); } } if ($entity && $this->parentCandidate->getCandidateFields($entity)) { return AccessResult::allowed()->setCacheMaxAge(0); } Loading Loading
entity_hierarchy.services.yml +1 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ services: arguments: ['@entity_field.manager', '@entity_type.bundle.info'] access_check.entity_hierarchy.has_fields: class: Drupal\entity_hierarchy\Routing\ReorderChildrenAccess arguments: ['@entity_hierarchy.information.parent_candidate', '@current_route_match'] arguments: ['@entity_hierarchy.information.parent_candidate', '@current_route_match', '@entity_type.manager'] tags: - { name: access_check } entity_hierarchy.entity_tree_node_mapper: Loading
src/Routing/ReorderChildrenAccess.php +26 −1 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ namespace Drupal\entity_hierarchy\Routing; use Drupal\Core\Access\AccessCheckInterface; use Drupal\Core\Access\AccessResult; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\entity_hierarchy\Information\ParentCandidateInterface; Loading @@ -29,6 +31,13 @@ class ReorderChildrenAccess implements AccessCheckInterface { */ protected $parentCandidate; /** * Entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** * Constructs a new ReorderChildrenAccess object. * Loading @@ -37,9 +46,10 @@ class ReorderChildrenAccess implements AccessCheckInterface { * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch * Route match. */ public function __construct(ParentCandidateInterface $parentCandidate, RouteMatchInterface $routeMatch) { public function __construct(ParentCandidateInterface $parentCandidate, RouteMatchInterface $routeMatch, EntityTypeManagerInterface $entityTypeManager) { $this->routeMatch = $routeMatch; $this->parentCandidate = $parentCandidate; $this->entityTypeManager = $entityTypeManager; } /** Loading @@ -65,6 +75,21 @@ class ReorderChildrenAccess implements AccessCheckInterface { 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 a user has configured a local task with views at e.g. // node/{node}/media then the {node} object isn't upcast. // @todo revisit this when // https://www.drupal.org/project/drupal/issues/2528166 is resolved if (!$entity instanceof EntityInterface) { $storage = $this->entityTypeManager->getStorage($entity_type); $entity = $storage->load($entity); if (!$entity) { // At this point we can't proceed so we err on the side of caution and // deny access to the tab. return AccessResult::forbidden(); } } if ($entity && $this->parentCandidate->getCandidateFields($entity)) { return AccessResult::allowed()->setCacheMaxAge(0); } Loading