diff --git a/core/lib/Drupal/Core/Entity/EntityAccessCheck.php b/core/lib/Drupal/Core/Entity/EntityAccessCheck.php index d15b7f5..99bba7c 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessCheck.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessCheck.php @@ -48,7 +48,8 @@ public function access(Route $route, RouteMatchInterface $route_match, AccountIn $parameters = $route_match->getParameters(); // If there is valid entity of the given entity type, check its access. foreach ($route->getOption('parameters') as $name => $options) { - if (isset($options['type']) && $options['type'] == 'entity:' . $entity_type && ($entity = $parameters->get($name)) && $entity instanceof EntityInterface) { + $option_entity_type = $this->getEntityTypeFromDefaults($options, $route_match->getRawParameters()->all()); + if (isset($options['type']) && $option_entity_type == $entity_type && ($entity = $parameters->get($name)) && $entity instanceof EntityInterface) { return $entity->access($operation, $account, TRUE); } } @@ -58,4 +59,26 @@ public function access(Route $route, RouteMatchInterface $route_match, AccountIn return AccessResult::neutral(); } + /** + * Determines the entity type ID given a route definition and route defaults. + * + * @param mixed $definition + * The parameter definition provided in the route options. + * @param array $defaults + * The route defaults array. + * + * @return string + * The entity type ID. + */ + protected function getEntityTypeFromDefaults($definition, array $defaults) { + $entity_type_id = substr($definition['type'], strlen('entity:')); + + // If the entity type is dynamic, it will be pulled from the route defaults. + if (strpos($entity_type_id, '{') === 0) { + $entity_type_slug = substr($entity_type_id, 1, -1); + $entity_type_id = $defaults[$entity_type_slug]; + } + return $entity_type_id; + } + }