diff --git a/core/core.services.yml b/core/core.services.yml index 4e81fbc..73c7873 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -196,7 +196,7 @@ services: arguments: ['@request_stack', '@string_translation', '@csrf_token', '@logger.channel.form'] form_submitter: class: Drupal\Core\Form\FormSubmitter - arguments: ['@request_stack', '@url_generator', '@current_route_match'] + arguments: ['@request_stack', '@url_generator'] form_cache: class: Drupal\Core\Form\FormCache arguments: ['@app.root', '@keyvalue.expirable', '@module_handler', '@current_user', '@csrf_token', '@logger.channel.form', '@config.factory', '@request_stack', '@page_cache_request_policy'] diff --git a/core/lib/Drupal/Core/Form/FormSubmitter.php b/core/lib/Drupal/Core/Form/FormSubmitter.php index ddb0fc6..42c33a9 100644 --- a/core/lib/Drupal/Core/Form/FormSubmitter.php +++ b/core/lib/Drupal/Core/Form/FormSubmitter.php @@ -12,7 +12,6 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Drupal\Core\Routing\UrlGeneratorInterface; -use Drupal\Core\Routing\RouteMatchInterface; /** * Provides submission processing for forms. @@ -34,24 +33,15 @@ class FormSubmitter implements FormSubmitterInterface { protected $requestStack; /** - * The current route match. - * - * @var \Drupal\Core\Routing\RouteMatchInterface - */ - protected $currentRouteMatch; - - /** * Constructs a new FormValidator. * * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack. * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator - * @param \Drupal\Core\Routing\RouteMatchInterface $current_route_match */ - public function __construct(RequestStack $request_stack, UrlGeneratorInterface $url_generator, RouteMatchInterface $current_route_match) { + public function __construct(RequestStack $request_stack, UrlGeneratorInterface $url_generator) { $this->requestStack = $request_stack; $this->urlGenerator = $url_generator; - $this->currentRouteMatch = $current_route_match; } /** @@ -146,16 +136,7 @@ public function redirectForm(FormStateInterface $form_state) { } // If no redirect was specified, redirect to the current path. elseif ($redirect === NULL) { - $request = $this->requestStack->getCurrentRequest(); - - $url = $this->urlGenerator->generateFromRoute( - $this->currentRouteMatch->getRouteName(), - $this->currentRouteMatch->getRawParameters()->all(), - array( - 'query' => $request->query->all(), - 'absolute' => TRUE, - ) - ); + $url = $this->requestStack->getCurrentRequest()->getUri(); } if ($url) { diff --git a/core/modules/system/tests/modules/theme_test/theme_test.services.yml b/core/modules/system/tests/modules/theme_test/theme_test.services.yml index 56c0ef7..add8b4c 100644 --- a/core/modules/system/tests/modules/theme_test/theme_test.services.yml +++ b/core/modules/system/tests/modules/theme_test/theme_test.services.yml @@ -1,8 +1,7 @@ services: theme_test.subscriber: class: Drupal\theme_test\EventSubscriber\ThemeTestSubscriber - arguments: - - @current_route_match + arguments: [@current_route_match] tags: - { name: event_subscriber } diff --git a/core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php b/core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php index 4b7715e..b10d41e 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php @@ -14,7 +14,6 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpFoundation\ParameterBag; /** * @coversDefaultClass \Drupal\Core\Form\FormSubmitter @@ -30,19 +29,11 @@ class FormSubmitterTest extends UnitTestCase { protected $urlGenerator; /** - * The mocked URL generator. - * - * @var \PHPUnit_Framework_MockObject_MockObject|\Drupal\Core\Routing\RouteMatchInterface - */ - protected $routeMatch; - - /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); - $this->routeMatch = $this->getMock('Drupal\Core\Routing\RouteMatchInterface'); } /** @@ -111,25 +102,14 @@ public function providerTestHandleFormSubmissionWithResponses() { */ public function testRedirectWithNull() { $form_submitter = $this->getFormSubmitter(); - $this->urlGenerator->expects($this->once()) - ->method('generateFromRoute') - ->with('', [], array('query' => array(), 'absolute' => TRUE)) - ->willReturn(''); - - $this->routeMatch->expects($this->once()) - ->method('getRouteName') - ->willReturn(''); - $this->routeMatch->expects($this->once()) - ->method('getRawParameters') - ->willReturn(new ParameterBag()); $form_state = $this->getMock('Drupal\Core\Form\FormStateInterface'); $form_state->expects($this->once()) ->method('getRedirect') ->willReturn(NULL); - $redirect = $form_submitter->redirectForm($form_state); - $this->assertSame('', $redirect->getTargetUrl()); + // If we have no redirect, we redirect to the current URL. + $this->assertSame('http://localhost/test-path', $redirect->getTargetUrl()); $this->assertSame(303, $redirect->getStatusCode()); } @@ -251,9 +231,9 @@ public function testExecuteSubmitHandlers() { */ protected function getFormSubmitter() { $request_stack = new RequestStack(); - $request_stack->push(new Request()); + $request_stack->push(Request::create('/test-path')); return $this->getMockBuilder('Drupal\Core\Form\FormSubmitter') - ->setConstructorArgs(array($request_stack, $this->urlGenerator, $this->routeMatch)) + ->setConstructorArgs(array($request_stack, $this->urlGenerator)) ->setMethods(array('batchGet', 'drupalInstallationAttempted')) ->getMock(); } diff --git a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php index 54f6a92..2386eb2 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php +++ b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php @@ -138,7 +138,6 @@ protected function setUp() { $this->formCache = $this->getMock('Drupal\Core\Form\FormCacheInterface'); $this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); - $this->routeMatch = $this->getMock('Drupal\Core\Routing\RouteMatchInterface'); $this->classResolver = $this->getClassResolverStub(); $this->csrfToken = $this->getMockBuilder('Drupal\Core\Access\CsrfTokenGenerator') ->disableOriginalConstructor() @@ -158,7 +157,7 @@ protected function setUp() { ->setMethods(array('drupalSetMessage')) ->getMock(); $this->formSubmitter = $this->getMockBuilder('Drupal\Core\Form\FormSubmitter') - ->setConstructorArgs(array($this->requestStack, $this->urlGenerator, $this->routeMatch)) + ->setConstructorArgs(array($this->requestStack, $this->urlGenerator)) ->setMethods(array('batchGet', 'drupalInstallationAttempted')) ->getMock(); $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));