Skip to content
Snippets Groups Projects
Commit c050f6e9 authored by catch's avatar catch
Browse files

Issue #2706241 by mglaman, Spokje, Chi, DamienMcKenna, JeroenT, ankithashetty,...

Issue #2706241 by mglaman, Spokje, Chi, DamienMcKenna, JeroenT, ankithashetty, lslinnet, george.karaivanov, Rade, rteijeiro, nplowman, Wim Leers: AccessAwareRouter does not respect HTTP method
parent 9bc5e07a
No related branches found
No related tags found
No related merge requests found
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
use Drupal\Core\Routing\RouteObjectInterface; use Drupal\Core\Routing\RouteObjectInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Exception\ExceptionInterface;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface; use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
/** /**
...@@ -137,10 +137,7 @@ protected function isAdminPath(Request $request) { ...@@ -137,10 +137,7 @@ protected function isAdminPath(Request $request) {
$path = $this->pathProcessorManager->processInbound(urldecode(rtrim($cloned_request->getPathInfo(), '/')), $cloned_request); $path = $this->pathProcessorManager->processInbound(urldecode(rtrim($cloned_request->getPathInfo(), '/')), $cloned_request);
$attributes = $this->router->match($path); $attributes = $this->router->match($path);
} }
catch (ResourceNotFoundException $e) { catch (ExceptionInterface | HttpException) {
return FALSE;
}
catch (AccessDeniedHttpException $e) {
return FALSE; return FALSE;
} }
$route_object = $attributes[RouteObjectInterface::ROUTE_OBJECT]; $route_object = $attributes[RouteObjectInterface::ROUTE_OBJECT];
......
<?php
namespace Drupal\user_language_test\Controller;
/**
* Returns responses for User Language Test routes.
*/
class UserLanguageTestController {
/**
* Builds the response.
*/
public function buildPostResponse() {
return ['#markup' => 'It works!'];
}
}
<?php
namespace Drupal\user_language_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Provides a User Language Test form.
*/
class UserLanguageTestForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'user_language_test';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#action'] = Url::fromRoute('user_language_test.post_response')->toString();
$form['actions'] = [
'#type' => 'actions',
'submit' => [
'#type' => 'submit',
'#value' => $this->t('Send'),
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
}
}
name: 'User language tests'
type: module
description: 'Support module for user language testing.'
package: Testing
version: VERSION
user_language_test.post_response:
path: '/user-language-test/post'
defaults:
_controller: Drupal\user_language_test\Controller\UserLanguageTestController::buildPostResponse
methods: [post]
options:
_admin_route: TRUE
requirements:
_access: 'TRUE'
user_language_test.form:
path: '/user-language-test/form'
defaults:
_form: 'Drupal\user_language_test\Form\UserLanguageTestForm'
requirements:
_access: 'TRUE'
...@@ -31,7 +31,7 @@ class UserAdminLanguageTest extends BrowserTestBase { ...@@ -31,7 +31,7 @@ class UserAdminLanguageTest extends BrowserTestBase {
* *
* @var array * @var array
*/ */
protected static $modules = ['user', 'language', 'language_test']; protected static $modules = ['user', 'language', 'language_test', 'user_language_test'];
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -156,6 +156,13 @@ public function testActualNegotiation() { ...@@ -156,6 +156,13 @@ public function testActualNegotiation() {
$this->drupalGet('xx/' . $path); $this->drupalGet('xx/' . $path);
$this->assertSession()->pageTextContains('Language negotiation method: language-user-admin'); $this->assertSession()->pageTextContains('Language negotiation method: language-user-admin');
// Make sure 'language-user-admin' plugin does not fail when a route is
// restricted to POST requests and language negotiation with the admin
// language method is used.
$this->drupalGet('/user-language-test/form');
$this->submitForm([], 'Send');
$this->assertSession()->statusCodeEquals(200);
// Unset the preferred language code for the user. // Unset the preferred language code for the user.
$edit = []; $edit = [];
$edit['preferred_admin_langcode'] = ''; $edit['preferred_admin_langcode'] = '';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment