diff --git a/core/lib/Drupal/Core/Entity/EntityAccessCheck.php b/core/lib/Drupal/Core/Entity/EntityAccessCheck.php index 99bba7c..04412e9 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessCheck.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessCheck.php @@ -45,40 +45,17 @@ public function access(Route $route, RouteMatchInterface $route_match, AccountIn // Split the entity type and the operation. $requirement = $route->getRequirement('_entity_access'); list($entity_type, $operation) = explode('.', $requirement); - $parameters = $route_match->getParameters(); // If there is valid entity of the given entity type, check its access. - foreach ($route->getOption('parameters') as $name => $options) { - $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) { + $parameters = $route_match->getParameters(); + if ($parameters->has($entity_type)) { + $entity = $parameters->get($entity_type); + if ($entity instanceof EntityInterface) { return $entity->access($operation, $account, TRUE); } } - // No opinion, so other access checks should decide if access should be // allowed or not. 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; - } - } diff --git a/core/modules/system/tests/modules/entity_test/entity_test.routing.yml b/core/modules/system/tests/modules/entity_test/entity_test.routing.yml index 4759947..542a14e 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.routing.yml +++ b/core/modules/system/tests/modules/entity_test/entity_test.routing.yml @@ -15,7 +15,7 @@ entity.entity_test.render_options: defaults: _entity_view: 'entity_test.full' requirements: - _entity_access: 'entity_test.view' + _entity_access: 'foo.view' entity.entity_test.render_no_view_mode: path: '/entity_test_no_view_mode/{entity_test}' diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php index 144899f..23a286c 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php @@ -42,7 +42,7 @@ protected function setUp() { * Tests the method for checking access to routes. */ public function testAccess() { - $route = new Route('/foo/{var_name}', [], ['_entity_access' => 'node.update'], ['parameters' => ['var_name' => ['type' => 'entity:node']]]); + $route = new Route('/foo/{var_name}', [], ['_entity_access' => 'var_name.update'], ['parameters' => ['var_name' => ['type' => 'entity:node']]]); /** @var \Drupal\Core\Session\AccountInterface $account */ $account = $this->prophesize(AccountInterface::class)->reveal(); @@ -63,10 +63,9 @@ public function testAccess() { /** * @covers ::access - * @covers ::getEntityTypeFromDefaults */ public function testAccessWithTypePlaceholder() { - $route = new Route('/foo/{entity_type}/{var_name}', [], ['_entity_access' => 'node.update'], ['parameters' => ['var_name' => ['type' => 'entity:{entity_type}']]]); + $route = new Route('/foo/{entity_type}/{var_name}', [], ['_entity_access' => 'var_name.update'], ['parameters' => ['var_name' => ['type' => 'entity:{entity_type}']]]); /** @var \Drupal\Core\Session\AccountInterface $account */ $account = $this->prophesize(AccountInterface::class)->reveal();