Issue #2752463 by tstoeckler: EntityResolverManager::setParametersFromEntityInformation() sets parameter info for non-existing parameters

8.3.x
Nathaniel Catchpole 2016-10-19 11:37:56 +01:00
parent 182f8fd18b
commit 2f7924b3ab
2 changed files with 25 additions and 1 deletions

View File

@ -166,7 +166,10 @@ class EntityResolverManager {
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

View File

@ -416,6 +416,27 @@ class EntityResolverManagerTest extends UnitTestCase {
$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.
*/