Commit 9bc59ded authored by alexpott's avatar alexpott

Issue #2776055 by claudiu.cristea: Entity form/view route errors when a...

Issue #2776055 by claudiu.cristea: Entity form/view route errors when a non-entity parameter comes first
parent f18da3e5
......@@ -172,7 +172,7 @@ protected function setParametersFromEntityInformation(Route $route) {
// 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'])) {
if (isset($info['type']) && (strpos($info['type'], 'entity:') === 0)) {
// The parameter types are in the form 'entity:$entity_type'.
list(, $parameter_entity_type) = explode(':', $info['type'], 2);
if ($parameter_entity_type == $entity_type) {
......
......@@ -384,6 +384,38 @@ public function testSetRouteOptionsWithEntityFormRoute() {
$this->assertEquals(array('entity_test' => array('type' => 'entity:entity_test')), $parameters);
}
/**
* Tests an _entity_form route where a non-entity parameter is first.
*
* The {argument} preceding {entity_test} in route path, is upcasting with a
* custom param converter.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
* @covers ::getEntityTypes
* @covers ::setParametersFromReflection
* @covers ::setParametersFromEntityInformation
*/
public function testSetRouteOptionsWithEntityFormRouteAndArgument() {
$this->setupEntityTypes();
$route = new Route('/example/{argument}/{entity_test}', [
'_entity_form' => 'entity_test.edit',
]);
// Add {argument} parameter configuration. In this case {argument} is
// upcasted by a custom param converter 'argument_type'.
$route->setOption('parameters', ['argument' => ['type' => 'argument_type']]);
$defaults = $route->getDefaults();
$this->entityResolverManager->setRouteOptions($route);
$this->assertEquals($defaults, $route->getDefaults());
$parameters = $route->getOption('parameters');
$expect = [
'argument' => ['type' => 'argument_type'],
'entity_test' => ['type' => 'entity:entity_test'],
];
$this->assertEquals($expect, $parameters);
}
/**
* Creates the entity manager mock returning entity type objects.
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment