diff --git a/core/lib/Drupal/Core/Entity/EntityResolverManager.php b/core/lib/Drupal/Core/Entity/EntityResolverManager.php index 79e62d1c3ae9bc1459a72ca1077d7cc35c9c25d3..847a480e4c9e48f494a0ca89851f69da30e1b3a0 100644 --- a/core/lib/Drupal/Core/Entity/EntityResolverManager.php +++ b/core/lib/Drupal/Core/Entity/EntityResolverManager.php @@ -166,7 +166,10 @@ protected function setParametersFromEntityInformation(Route $route) { list($entity_type) = explode('.', $entity_form, 2); } - if (isset($entity_type) && isset($this->getEntityTypes()[$entity_type])) { + // Do not add parameter information if the route does not declare a + // parameter in the first place. This is the case for add forms, for + // example. + if (isset($entity_type) && isset($this->getEntityTypes()[$entity_type]) && (strpos($route->getPath(), '{' . $entity_type . '}') !== FALSE)) { $parameter_definitions = $route->getOption('parameters') ?: array(); // First try to figure out whether there is already a parameter upcasting diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php index bacab58af1289b12ce8ad48a1ab045bc1d7109e2..6e164708b94d11b12f5dd5a59be980a09c2f6d89 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php @@ -416,6 +416,27 @@ public function testSetRouteOptionsWithEntityFormRouteAndArgument() { $this->assertEquals($expect, $parameters); } + /** + * Tests setRouteOptions() with an _entity_form route for an add form. + * + * @covers ::setRouteOptions + * @covers ::getControllerClass + * @covers ::getEntityTypes + * @covers ::setParametersFromReflection + * @covers ::setParametersFromEntityInformation + */ + public function testSetRouteOptionsWithEntityAddFormRoute() { + $this->setupEntityTypes(); + $route = new Route('/example/add', array( + '_entity_form' => 'entity_test.add', + )); + + $defaults = $route->getDefaults(); + $this->entityResolverManager->setRouteOptions($route); + $this->assertEquals($defaults, $route->getDefaults()); + $this->assertFalse($route->hasOption('parameters')); + } + /** * Creates the entity manager mock returning entity type objects. */