Commit 12feabd3 authored by catch's avatar catch

Issue #2330929 by znerol: Remove the request from parameter converters.

parent 29c4def3
......@@ -205,7 +205,7 @@ public function checkNamedRoute($route_name, array $parameters = array(), Accoun
$parameters += $route->getDefaults();
$route_request->attributes->set('_raw_variables', new ParameterBag($parameters));
$parameters[RouteObjectInterface::ROUTE_OBJECT] = $route;
$route_request->attributes->add($this->paramConverterManager->convert($parameters, $route_request));
$route_request->attributes->add($this->paramConverterManager->convert($parameters));
}
return $this->check($route, $route_request, $account);
}
......
......@@ -8,7 +8,6 @@
namespace Drupal\Core\ParamConverter;
use Drupal\Core\Routing\AdminContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
......@@ -63,7 +62,7 @@ public function __construct(EntityManagerInterface $entity_manager, ConfigFactor
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults, Request $request) {
public function convert($value, $definition, $name, array $defaults) {
$entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults);
// If the entity type is dynamic, confirm it to be a config entity. Static
......@@ -71,7 +70,7 @@ public function convert($value, $definition, $name, array $defaults, Request $re
if (strpos($definition['type'], 'entity:{') === 0) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
if (!$entity_type->isSubclassOf('\Drupal\Core\Config\Entity\ConfigEntityInterface')) {
return parent::convert($value, $definition, $name, $defaults, $request);
return parent::convert($value, $definition, $name, $defaults);
}
}
......
......@@ -8,7 +8,6 @@
namespace Drupal\Core\ParamConverter;
use Drupal\Core\Entity\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
/**
......@@ -62,7 +61,7 @@ public function __construct(EntityManagerInterface $entity_manager) {
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults, Request $request) {
public function convert($value, $definition, $name, array $defaults) {
$entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults);
if ($storage = $this->entityManager->getStorage($entity_type_id)) {
return $storage->load($value);
......
......@@ -9,7 +9,6 @@
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Drupal\Component\Plugin\Exception\PluginException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
/**
......@@ -37,7 +36,7 @@ public function __construct(MenuLinkManagerInterface $menu_link_manager) {
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults, Request $request) {
public function convert($value, $definition, $name, array $defaults) {
if ($value) {
try {
return $this->menuLinkManager->createInstance($value);
......
......@@ -7,7 +7,6 @@
namespace Drupal\Core\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
/**
......@@ -26,13 +25,11 @@
* The name of the parameter.
* @param array $defaults
* The route defaults array.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*
* @return mixed|null
* The converted parameter value.
*/
public function convert($value, $definition, $name, array $defaults, Request $request);
public function convert($value, $definition, $name, array $defaults);
/**
* Determines if the converter applies to a specific route and variable.
......
......@@ -11,7 +11,6 @@
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\HttpFoundation\Request;
/**
* Manages converter services for converting request parameters to full objects.
......@@ -81,7 +80,7 @@ public function setRouteParameterConverters(RouteCollection $routes) {
/**
* {@inheritdoc}
*/
public function convert(array $defaults, Request $request) {
public function convert(array $defaults) {
/** @var $route \Symfony\Component\Routing\Route */
$route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
......@@ -104,7 +103,7 @@ public function convert(array $defaults, Request $request) {
// If a converter returns NULL it means that the parameter could not be
// converted.
$defaults[$name] = $this->getConverter($definition['converter'])->convert($defaults[$name], $definition, $name, $defaults, $request);
$defaults[$name] = $this->getConverter($definition['converter'])->convert($defaults[$name], $definition, $name, $defaults);
if (!isset($defaults[$name])) {
throw new ParamNotConvertedException(sprintf('The "%s" parameter was not converted for the path "%s" (route name: "%s")', $name, $route->getPath(), $defaults[RouteObjectInterface::ROUTE_NAME]));
}
......@@ -114,4 +113,3 @@ public function convert(array $defaults, Request $request) {
}
}
......@@ -7,7 +7,6 @@
namespace Drupal\Core\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouteCollection;
/**
......@@ -54,8 +53,6 @@ public function setRouteParameterConverters(RouteCollection $routes);
*
* @param array $defaults
* The route defaults array.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
*
* @throws \Drupal\Core\ParamConverter\ParamNotConvertedException
* If one of the assigned converters returned NULL because the given
......@@ -64,6 +61,6 @@ public function setRouteParameterConverters(RouteCollection $routes);
* @return array
* The modified defaults.
*/
public function convert(array $defaults, Request $request);
public function convert(array $defaults);
}
......@@ -45,7 +45,7 @@ public function __construct(ParamConverterManagerInterface $param_converter_mana
*/
public function enhance(array $defaults, Request $request) {
$defaults['_raw_variables'] = $this->copyRawVariables($defaults);
return $this->paramConverterManager->convert($defaults, $request);
return $this->paramConverterManager->convert($defaults);
}
/**
......
......@@ -9,7 +9,6 @@
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
/**
......@@ -37,7 +36,7 @@ public function __construct(LanguageManagerInterface $language_manager) {
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults, Request $request) {
public function convert($value, $definition, $name, array $defaults) {
if (!empty($value)) {
return $this->languageManager->getLanguage($value);
}
......
......@@ -8,7 +8,6 @@
namespace Drupal\node\ParamConverter;
use Drupal\Core\Entity\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Drupal\user\TempStoreFactory;
......@@ -38,7 +37,7 @@ public function __construct(TempStoreFactory $temp_store_factory) {
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults, Request $request) {
public function convert($value, $definition, $name, array $defaults) {
$store = $this->tempStoreFactory->get('node_preview');
if ($form_state = $store->get($value)) {
return $form_state->getFormObject()->getEntity();
......
......@@ -9,7 +9,6 @@
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\ParamConverter\EntityConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Drupal\user\TempStoreFactory;
......@@ -55,8 +54,8 @@ public function __construct(EntityManagerInterface $entity_manager, TempStoreFac
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults, Request $request) {
if (!$entity = parent::convert($value, $definition, $name, $defaults, $request)) {
public function convert($value, $definition, $name, array $defaults) {
if (!$entity = parent::convert($value, $definition, $name, $defaults)) {
return;
}
......
......@@ -61,7 +61,7 @@ public function testEnhance() {
$this->paramConverterManager->expects($this->any())
->method('convert')
->with($this->isType('array'), $this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
->with($this->isType('array'))
->will($this->returnValue($expected));
$result = $this->paramConversionEnhancer->enhance($defaults, new Request());
......@@ -82,7 +82,7 @@ public function testCopyRawVariables() {
$defaults['bar'] = &$defaults['id'];
$this->paramConverterManager->expects($this->any())
->method('convert')
->with($this->isType('array'), $this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
->with($this->isType('array'))
->will($this->returnCallback(function ($defaults) {
// Convert the mirrored default to another value.
$defaults['bar'] = '2';
......
......@@ -9,7 +9,6 @@
use Drupal\Core\ParamConverter\EntityConverter;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
/**
......@@ -95,7 +94,7 @@ public function testConvert($value, array $definition, array $defaults, $expecte
['invalid_id', NULL],
]);
$this->assertEquals($expected_result, $this->entityConverter->convert($value, $definition, 'foo', $defaults, new Request()));
$this->assertEquals($expected_result, $this->entityConverter->convert($value, $definition, 'foo', $defaults));
}
/**
......@@ -124,7 +123,7 @@ public function testConvertWithInvalidEntityType() {
->with('invalid_id')
->willThrowException(new \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException('invalid_id'));
$this->entityConverter->convert('id', ['type' => 'entity:invalid_id'], 'foo', ['foo' => 'id'], new Request());
$this->entityConverter->convert('id', ['type' => 'entity:invalid_id'], 'foo', ['foo' => 'id']);
}
/**
......@@ -134,7 +133,7 @@ public function testConvertWithInvalidEntityType() {
* @expectedExceptionMessage The "foo" parameter was not converted because the "invalid_id" parameter is missing
*/
public function testConvertWithInvalidDynamicEntityType() {
$this->entityConverter->convert('id', ['type' => 'entity:{invalid_id}'], 'foo', ['foo' => 'id'], new Request());
$this->entityConverter->convert('id', ['type' => 'entity:{invalid_id}'], 'foo', ['foo' => 'id']);
}
}
......@@ -10,7 +10,6 @@
use Drupal\Core\ParamConverter\ParamConverterManager;
use Drupal\Tests\UnitTestCase;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
......@@ -199,11 +198,11 @@ public function testConvert() {
$converter = $this->getMock('Drupal\Core\ParamConverter\ParamConverterInterface');
$converter->expects($this->any())
->method('convert')
->with(1, $this->isType('array'), 'id', $this->isType('array'), $this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
->with(1, $this->isType('array'), 'id', $this->isType('array'))
->will($this->returnValue('something_better!'));
$this->manager->addConverter($converter, 'test_convert');
$result = $this->manager->convert($defaults, new Request());
$result = $this->manager->convert($defaults);
$this->assertEquals($expected, $result);
}
......@@ -220,7 +219,7 @@ public function testConvertNoConverting() {
$expected = $defaults;
$result = $this->manager->convert($defaults, new Request());
$result = $this->manager->convert($defaults);
$this->assertEquals($expected, $result);
}
......@@ -248,11 +247,11 @@ public function testConvertMissingParam() {
$converter = $this->getMock('Drupal\Core\ParamConverter\ParamConverterInterface');
$converter->expects($this->any())
->method('convert')
->with(1, $this->isType('array'), 'id', $this->isType('array'), $this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
->with(1, $this->isType('array'), 'id', $this->isType('array'))
->will($this->returnValue(NULL));
$this->manager->addConverter($converter, 'test_convert');
$this->manager->convert($defaults, new Request());
$this->manager->convert($defaults);
}
}
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