diff --git a/core/lib/Drupal/Core/Entity/EntityResolverManager.php b/core/lib/Drupal/Core/Entity/EntityResolverManager.php index 9a2bde2..2531b7d 100644 --- a/core/lib/Drupal/Core/Entity/EntityResolverManager.php +++ b/core/lib/Drupal/Core/Entity/EntityResolverManager.php @@ -150,6 +150,18 @@ protected function setParametersFromEntityInformation(Route $route) { } if (isset($entity_type) && $this->entityManager->getDefinition($entity_type)) { $parameter_definitions = $route->getOption('parameters') ?: array(); + + // First try to figure out whether there is already a parameter upcasting + // the same entity type already. + foreach ($parameter_definitions as $info) { + if (isset($info['type'])) { + list(, $parameter_entity_type) = explode(':', $info['type']); + if ($parameter_entity_type == $entity_type) { + return; + } + } + } + if (!isset($parameter_definitions[$entity_type])) { $parameter_definitions[$entity_type] = array(); } diff --git a/core/modules/node/lib/Drupal/node/Access/NodeAddAccessCheck.php b/core/modules/node/lib/Drupal/node/Access/NodeAddAccessCheck.php index 8d72223..451b066 100644 --- a/core/modules/node/lib/Drupal/node/Access/NodeAddAccessCheck.php +++ b/core/modules/node/lib/Drupal/node/Access/NodeAddAccessCheck.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Routing\Access\AccessInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\node\NodeTypeInterface; use Symfony\Component\Routing\Route; use Symfony\Component\HttpFoundation\Request; @@ -41,8 +42,8 @@ public function __construct(EntityManagerInterface $entity_manager) { public function access(Route $route, Request $request, AccountInterface $account) { $access_controller = $this->entityManager->getAccessController('node'); // If a node type is set on the request, just check that. - if ($request->attributes->has('node_type')) { - return $access_controller->createAccess($request->attributes->get('node_type')->type, $account) ? static::ALLOW : static::DENY; + if (($node_type = $request->attributes->get('node_type')) && $node_type instanceof NodeTypeInterface) { + return $access_controller->createAccess($node_type->type, $account) ? static::ALLOW : static::DENY; } foreach (node_permissions_get_configured_types() as $type) { if ($access_controller->createAccess($type->type, $account)) { diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php index 6eba381..0909220 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php @@ -221,6 +221,37 @@ public function testSetRouteOptionsWithEntityFormNoUpcasting() { $this->assertEmpty($route->getOption('parameters')); } + /** + * Tests the setRouteOptions method with an _entity_view route. + * + * @covers ::setRouteOptions() + * @covers ::getController() + * @covers ::getEntityTypes() + * @covers ::setParametersFromReflection() + * @covers ::setParametersFromEntityInformation() + */ + public function testSetRouteOptionsWithEntityViewRouteAndManualParameters() { + $this->setupEntityTypes(); + $route = new Route('/example/{foo}', + array( + '_entity_view' => 'entity_test.view', + ), + array(), + array( + 'parameters' => array( + 'foo' => array( + 'type' => 'entity:entity_test', + ), + ), + ) + ); + + $defaults = $route->getDefaults(); + $this->entityResolverManager->setRouteOptions($route); + $this->assertEquals($defaults, $route->getDefaults()); + $parameters = $route->getOption('parameters'); + $this->assertEquals(array('foo' => array('type' => 'entity:entity_test')), $parameters); + } /** * Tests the setRouteOptions method with an _entity_view route.