Commit 1e08b50f authored by alexpott's avatar alexpott

Issue #2281619 by dawehner, tim.plunkett: Convert most direct usages within...

Issue #2281619 by dawehner, tim.plunkett: Convert most direct usages within module code of routing related request attributes to use RouteMatchInterface instead
parent 38b74276
...@@ -505,7 +505,7 @@ services: ...@@ -505,7 +505,7 @@ services:
- [fromRequestStack, ['@request_stack']] - [fromRequestStack, ['@request_stack']]
router.admin_context: router.admin_context:
class: Drupal\Core\Routing\AdminContext class: Drupal\Core\Routing\AdminContext
arguments: ['@request_stack'] arguments: ['@current_route_match']
router.route_provider: router.route_provider:
class: Drupal\Core\Routing\RouteProvider class: Drupal\Core\Routing\RouteProvider
arguments: ['@database', '@router.builder', '@state'] arguments: ['@database', '@router.builder', '@state']
......
...@@ -138,11 +138,15 @@ protected function createController($controller) { ...@@ -138,11 +138,15 @@ protected function createController($controller) {
*/ */
protected function doGetArguments(Request $request, $controller, array $parameters) { protected function doGetArguments(Request $request, $controller, array $parameters) {
$attributes = $request->attributes->all(); $attributes = $request->attributes->all();
$raw_parameters = $request->attributes->has('_raw_variables') ? $request->attributes->get('_raw_variables') : [];
$arguments = array(); $arguments = array();
foreach ($parameters as $param) { foreach ($parameters as $param) {
if (array_key_exists($param->name, $attributes)) { if (array_key_exists($param->name, $attributes)) {
$arguments[] = $attributes[$param->name]; $arguments[] = $attributes[$param->name];
} }
elseif (array_key_exists($param->name, $raw_parameters)) {
$arguments[] = $attributes[$param->name];
}
elseif ($param->getClass() && $param->getClass()->isInstance($request)) { elseif ($param->getClass() && $param->getClass()->isInstance($request)) {
$arguments[] = $request; $arguments[] = $request;
} }
...@@ -166,21 +170,6 @@ protected function doGetArguments(Request $request, $controller, array $paramete ...@@ -166,21 +170,6 @@ protected function doGetArguments(Request $request, $controller, array $paramete
throw new \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument (because there is no default value or because there is a non optional argument after this one).', $repr, $param->name)); throw new \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument (because there is no default value or because there is a non optional argument after this one).', $repr, $param->name));
} }
} }
// The parameter converter overrides the raw request attributes with the
// upcasted objects. However, it keeps a backup copy of the original, raw
// values in a special request attribute ('_raw_variables'). If a controller
// argument has a type hint, we pass it the upcasted object, otherwise we
// pass it the original, raw value.
if ($request->attributes->has('_raw_variables') && $raw = $request->attributes->get('_raw_variables')->all()) {
foreach ($parameters as $parameter) {
// Use the raw value if a parameter has no typehint.
if (!$parameter->getClass() && isset($raw[$parameter->name])) {
$position = $parameter->getPosition();
$arguments[$position] = $raw[$parameter->name];
}
}
}
return $arguments; return $arguments;
} }
......
...@@ -53,6 +53,13 @@ abstract class FormBase implements FormInterface, ContainerInjectionInterface { ...@@ -53,6 +53,13 @@ abstract class FormBase implements FormInterface, ContainerInjectionInterface {
*/ */
protected $loggerFactory; protected $loggerFactory;
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -135,6 +142,18 @@ protected function getRequest() { ...@@ -135,6 +142,18 @@ protected function getRequest() {
return $this->requestStack->getCurrentRequest(); return $this->requestStack->getCurrentRequest();
} }
/**
* Gets the route match.
*
* @return \Drupal\Core\Routing\RouteMatchInterface
*/
protected function getRouteMatch() {
if (!$this->routeMatch) {
$this->routeMatch = \Drupal::routeMatch();
}
return $this->routeMatch;
}
/** /**
* Sets the request stack object to use. * Sets the request stack object to use.
* *
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
namespace Drupal\Core\Routing; namespace Drupal\Core\Routing;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Route; use Symfony\Component\Routing\Route;
/** /**
...@@ -17,20 +15,20 @@ ...@@ -17,20 +15,20 @@
class AdminContext { class AdminContext {
/** /**
* The request stack * The route match.
* *
* @var \Symfony\Component\HttpFoundation\RequestStack * @var \Drupal\Core\Routing\RouteMatchInterface
*/ */
protected $requestStack; protected $routeMatch;
/** /**
* Construct a new admin context helper instance. * Construct a new admin context helper instance.
* *
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The request stack used to determine the current request. * The route match.
*/ */
public function __construct(RequestStack $request_stack) { public function __construct(RouteMatchInterface $route_match) {
$this->requestStack = $request_stack; $this->routeMatch = $route_match;
} }
/** /**
...@@ -45,7 +43,7 @@ public function __construct(RequestStack $request_stack) { ...@@ -45,7 +43,7 @@ public function __construct(RequestStack $request_stack) {
*/ */
public function isAdminRoute(Route $route = NULL) { public function isAdminRoute(Route $route = NULL) {
if (!$route) { if (!$route) {
$route = $this->getRouteFromRequest(); $route = $this->routeMatch->getRouteObject();
if (!$route) { if (!$route) {
return FALSE; return FALSE;
} }
...@@ -53,17 +51,4 @@ public function isAdminRoute(Route $route = NULL) { ...@@ -53,17 +51,4 @@ public function isAdminRoute(Route $route = NULL) {
return (bool) $route->getOption('_admin_route'); return (bool) $route->getOption('_admin_route');
} }
/**
* Extract the route object from the request if one is available.
*
* @return \Symfony\Component\Routing\Route
* The route object extracted from the current request.
*/
protected function getRouteFromRequest() {
$request = $this->requestStack->getCurrentRequest();
if ($request) {
return $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT);
}
}
} }
...@@ -132,4 +132,11 @@ public function getParentRouteMatch() { ...@@ -132,4 +132,11 @@ public function getParentRouteMatch() {
return $this->getRouteMatch($this->requestStack->getParentRequest()); return $this->getRouteMatch($this->requestStack->getParentRequest());
} }
/**
* {@inheritdoc}
*/
public function getRouteMatchFromRequest(Request $request) {
return $this->getRouteMatch($request);
}
} }
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
namespace Drupal\Core\Routing; namespace Drupal\Core\Routing;
use Symfony\Component\HttpFoundation\Request;
/** /**
* Defines an interface for a stack of route matches. * Defines an interface for a stack of route matches.
* *
...@@ -36,5 +38,15 @@ public function getMasterRouteMatch(); ...@@ -36,5 +38,15 @@ public function getMasterRouteMatch();
*/ */
public function getParentRouteMatch(); public function getParentRouteMatch();
} /**
* Returns a route match from a given request, if possible.
*
* @param \Symfony\Component\HttpFoundation\Request
* The request.
*
* @return \Drupal\Core\Routing\RouteMatchInterface|NULL
* THe matching route match, or NULL if there is no matching one.
*/
public function getRouteMatchFromRequest(Request $request);
}
...@@ -314,9 +314,9 @@ function comment_view_multiple($comments, $view_mode = 'full', $langcode = NULL) ...@@ -314,9 +314,9 @@ function comment_view_multiple($comments, $view_mode = 'full', $langcode = NULL)
* Implements hook_form_FORM_ID_alter() for field_ui_field_storage_add_form. * Implements hook_form_FORM_ID_alter() for field_ui_field_storage_add_form.
*/ */
function comment_form_field_ui_field_storage_add_form_alter(&$form, FormStateInterface $form_state) { function comment_form_field_ui_field_storage_add_form_alter(&$form, FormStateInterface $form_state) {
$request = \Drupal::request(); $route_match = \Drupal::routeMatch();
if ($form_state->get('entity_type_id') == 'comment' && $request->attributes->has('commented_entity_type')) { if ($form_state->get('entity_type_id') == 'comment' && $route_match->getParameter('commented_entity_type')) {
$form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($request->attributes->get('commented_entity_type'), $request->attributes->get('field_name')); $form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($route_match->getParameter('commented_entity_type'), $route_match->getParameter('field_name'));
} }
if (!_comment_entity_uses_integer_id($form_state->get('entity_type_id'))) { if (!_comment_entity_uses_integer_id($form_state->get('entity_type_id'))) {
// You cannot use comment fields on entity types with non-integer IDs. // You cannot use comment fields on entity types with non-integer IDs.
...@@ -328,9 +328,9 @@ function comment_form_field_ui_field_storage_add_form_alter(&$form, FormStateInt ...@@ -328,9 +328,9 @@ function comment_form_field_ui_field_storage_add_form_alter(&$form, FormStateInt
* Implements hook_form_FORM_ID_alter(). * Implements hook_form_FORM_ID_alter().
*/ */
function comment_form_field_ui_form_display_overview_form_alter(&$form, FormStateInterface $form_state) { function comment_form_field_ui_form_display_overview_form_alter(&$form, FormStateInterface $form_state) {
$request = \Drupal::request(); $route_match = \Drupal::routeMatch();
if ($form['#entity_type'] == 'comment' && $request->attributes->has('commented_entity_type')) { if ($form['#entity_type'] == 'comment' && $route_match->getParameter('commented_entity_type')) {
$form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($request->attributes->get('commented_entity_type'), $request->attributes->get('field_name')); $form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($route_match->getParameter('commented_entity_type'), $route_match->getParameter('field_name'));
} }
} }
...@@ -338,9 +338,9 @@ function comment_form_field_ui_form_display_overview_form_alter(&$form, FormStat ...@@ -338,9 +338,9 @@ function comment_form_field_ui_form_display_overview_form_alter(&$form, FormStat
* Implements hook_form_FORM_ID_alter(). * Implements hook_form_FORM_ID_alter().
*/ */
function comment_form_field_ui_display_overview_form_alter(&$form, FormStateInterface $form_state) { function comment_form_field_ui_display_overview_form_alter(&$form, FormStateInterface $form_state) {
$request = \Drupal::request(); $route_match = \Drupal::routeMatch();
if ($form['#entity_type'] == 'comment' && $request->attributes->has('commented_entity_type')) { if ($form['#entity_type'] == 'comment' && $route_match->getParameter('commented_entity_type')) {
$form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($request->attributes->get('commented_entity_type'), $request->attributes->get('field_name')); $form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($route_match->getParameter('commented_entity_type'), $route_match->getParameter('field_name'));
} }
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
......
...@@ -281,6 +281,8 @@ public function hasTranslation(LanguageInterface $language); ...@@ -281,6 +281,8 @@ public function hasTranslation(LanguageInterface $language);
/** /**
* Populate the config mapper with request data. * Populate the config mapper with request data.
* *
* @todo Replace $request with RouteMatch https://www.drupal.org/node/2295255.
*
* @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\HttpFoundation\Request $request
* Page request object. * Page request object.
*/ */
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
/** /**
* Base class for entity translation controllers. * Base class for entity translation controllers.
...@@ -37,16 +37,15 @@ public function prepareTranslation(ContentEntityInterface $entity, LanguageInter ...@@ -37,16 +37,15 @@ public function prepareTranslation(ContentEntityInterface $entity, LanguageInter
/** /**
* Builds the translations overview page. * Builds the translations overview page.
* *
* @param \Symfony\Component\HttpFoundation\Request $request * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The request object from which to extract the entity type. * The route match.
* @param string $entity_type_id * @param string $entity_type_id
* (optional) The entity type ID. * (optional) The entity type ID.
* * @return array Array of page elements to render.
* @return array * Array of page elements to render.
* Array of page elements to render.
*/ */
public function overview(Request $request, $entity_type_id = NULL) { public function overview(RouteMatchInterface $route_match, $entity_type_id = NULL) {
$entity = $request->attributes->get($entity_type_id); $entity = $route_match->getParameter($entity_type_id);
$account = $this->currentUser(); $account = $this->currentUser();
$handler = $this->entityManager()->getHandler($entity_type_id, 'translation'); $handler = $this->entityManager()->getHandler($entity_type_id, 'translation');
...@@ -252,16 +251,16 @@ public function overview(Request $request, $entity_type_id = NULL) { ...@@ -252,16 +251,16 @@ public function overview(Request $request, $entity_type_id = NULL) {
* @param \Drupal\Core\Language\LanguageInterface $target * @param \Drupal\Core\Language\LanguageInterface $target
* The language of the translated values. Defaults to the current content * The language of the translated values. Defaults to the current content
* language. * language.
* @param \Symfony\Component\HttpFoundation\Request $request * @param \Drupal\Core\Routing\RouteMatchInterface
* The request object from which to extract the entity type. * The route match object from which to extract the entity type.
* @param string $entity_type_id * @param string $entity_type_id
* (optional) The entity type ID. * (optional) The entity type ID.
* *
* @return array * @return array
* A processed form array ready to be rendered. * A processed form array ready to be rendered.
*/ */
public function add(LanguageInterface $source, LanguageInterface $target, Request $request, $entity_type_id = NULL) { public function add(LanguageInterface $source, LanguageInterface $target, RouteMatchInterface $route_match, $entity_type_id = NULL) {
$entity = $request->attributes->get($entity_type_id); $entity = $route_match->getParameter($entity_type_id);
// @todo Exploit the upcoming hook_entity_prepare() when available. // @todo Exploit the upcoming hook_entity_prepare() when available.
// See https://www.drupal.org/node/1810394. // See https://www.drupal.org/node/1810394.
...@@ -287,16 +286,16 @@ public function add(LanguageInterface $source, LanguageInterface $target, Reques ...@@ -287,16 +286,16 @@ public function add(LanguageInterface $source, LanguageInterface $target, Reques
* @param \Drupal\Core\Language\LanguageInterface $language * @param \Drupal\Core\Language\LanguageInterface $language
* The language of the translated values. Defaults to the current content * The language of the translated values. Defaults to the current content
* language. * language.
* @param \Symfony\Component\HttpFoundation\Request $request * @param \Drupal\Core\Routing\RouteMatchInterface
* The request object from which to extract the entity type. * The route match object from which to extract the entity type.
* @param string $entity_type_id * @param string $entity_type_id
* (optional) The entity type ID. * (optional) The entity type ID.
* *
* @return array * @return array
* A processed form array ready to be rendered. * A processed form array ready to be rendered.
*/ */
public function edit(LanguageInterface $language, Request $request, $entity_type_id = NULL) { public function edit(LanguageInterface $language, RouteMatchInterface $route_match, $entity_type_id = NULL) {
$entity = $request->attributes->get($entity_type_id); $entity = $route_match->getParameter($entity_type_id);
// @todo Provide a way to figure out the default form operation. Maybe like // @todo Provide a way to figure out the default form operation. Maybe like
// $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default'; // $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default';
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
/** /**
...@@ -40,9 +41,9 @@ public function getFormId() { ...@@ -40,9 +41,9 @@ public function getFormId() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $language = NULL) { public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, LanguageInterface $language = NULL) {
$this->entity = $this->getRequest()->attributes->get($entity_type_id); $this->entity = $this->getRouteMatch()->getParameter($entity_type_id);
$this->language = language_load($language); $this->language = $language;
return parent::buildForm($form, $form_state); return parent::buildForm($form, $form_state);
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\field_ui\Controller; namespace Drupal\field_ui\Controller;
use Drupal\Core\Entity\Controller\EntityListController; use Drupal\Core\Entity\Controller\EntityListController;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/** /**
...@@ -22,18 +23,18 @@ class FieldConfigListController extends EntityListController { ...@@ -22,18 +23,18 @@ class FieldConfigListController extends EntityListController {
* The entity type. * The entity type.
* @param string $bundle * @param string $bundle
* The entity bundle. * The entity bundle.
* @param \Symfony\Component\HttpFoundation\Request $request * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current request. * The current route match.
* *
* @return array * @return array
* A render array as expected by drupal_render(). * A render array as expected by drupal_render().
*/ */
public function listing($entity_type_id = NULL, $bundle = NULL, Request $request = NULL) { public function listing($entity_type_id = NULL, $bundle = NULL, RouteMatchInterface $route_match = NULL) {
if (!$bundle) { if (!$bundle) {
$entity_info = $this->entityManager()->getDefinition($entity_type_id); $entity_info = $this->entityManager()->getDefinition($entity_type_id);
$bundle = $request->attributes->get('_raw_variables')->get($entity_info->getBundleEntityType()); $bundle = $route_match->getRawParameter($entity_info->getBundleEntityType());
} }
return $this->entityManager()->getListBuilder('field_config')->render($entity_type_id, $bundle, $request); return $this->entityManager()->getListBuilder('field_config')->render($entity_type_id, $bundle);
} }
} }
...@@ -122,7 +122,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t ...@@ -122,7 +122,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
$form_state->set('entity_type_id', $entity_type_id); $form_state->set('entity_type_id', $entity_type_id);
} }
if (!$form_state->get('bundle')) { if (!$form_state->get('bundle')) {
$bundle = $bundle ?: $this->getRequest()->attributes->get('_raw_variables')->get($this->bundleEntityTypeId); $bundle = $bundle ?: $this->getRouteMatch()->getRawParameter($this->bundleEntityTypeId);
$form_state->set('bundle', $bundle); $form_state->set('bundle', $bundle);
} }
......
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
namespace Drupal\node\Plugin\views\argument_default; namespace Drupal\node\Plugin\views\argument_default;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\CacheablePluginInterface;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase; use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Default argument plugin to extract a node. * Default argument plugin to extract a node.
...@@ -23,11 +25,49 @@ ...@@ -23,11 +25,49 @@
*/ */
class Node extends ArgumentDefaultPluginBase implements CacheablePluginInterface { class Node extends ArgumentDefaultPluginBase implements CacheablePluginInterface {
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* Constructs a new Date instance.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->routeMatch = $route_match;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('current_route_match')
);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getArgument() { public function getArgument() {
if (($node = $this->view->getRequest()->attributes->get('node')) && $node instanceof NodeInterface) { if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
return $node->id(); return $node->id();
} }
} }
......
...@@ -31,11 +31,13 @@ class RequestHandler implements ContainerAwareInterface { ...@@ -31,11 +31,13 @@ class RequestHandler implements ContainerAwareInterface {
* The route match. * The route match.
* @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\HttpFoundation\Request $request
* The HTTP request object. * The HTTP request object.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* *
* @return \Symfony\Component\HttpFoundation\Response * @return \Symfony\Component\HttpFoundation\Response
* The response object. * The response object.
*/ */
public function handle(RouteMatchInterface $route_match, Request $request) { public function handle(RouteMatchInterface $route_match, Request $request, RouteMatchInterface $route_match) {
$plugin = $route_match->getRouteObject()->getDefault('_plugin'); $plugin = $route_match->getRouteObject()->getDefault('_plugin');
$method = strtolower($request->getMethod()); $method = strtolower($request->getMethod());
...@@ -76,7 +78,7 @@ public function handle(RouteMatchInterface $route_match, Request $request) { ...@@ -76,7 +78,7 @@ public function handle(RouteMatchInterface $route_match, Request $request) {
// Determine the request parameters that should be passed to the resource // Determine the request parameters that should be passed to the resource
// plugin. // plugin.
$route_parameters = $request->attributes->get('_route_params'); $route_parameters = $route_match->getParameters();
$parameters = array(); $parameters = array();
// Filter out all internal parameters starting with "_". // Filter out all internal parameters starting with "_".
foreach ($route_parameters as $key => $parameter) { foreach ($route_parameters as $key => $parameter) {
......
...@@ -893,8 +893,8 @@ function hook_ENTITY_TYPE_storage_load(array $entities) { ...@@ -893,8 +893,8 @@ function hook_ENTITY_TYPE_storage_load(array $entities) {
*/ */
function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity) { function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
if ($entity instanceof ContentEntityInterface && $entity->isTranslatable()) { if ($entity instanceof ContentEntityInterface && $entity->isTranslatable()) {
$attributes = \Drupal::request()->attributes; $route_match = \Drupal::routeMatch();
\Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()->getId(), $attributes->get('source_langcode')); \Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()->getId(), $route_match->getParameter('source_langcode'));
} }
} }
...@@ -909,8 +909,8 @@ function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity) { ...@@ -909,8 +909,8 @@ function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
*/ */
function hook_ENTITY_TYPE_presave(Drupal\Core\Entity\EntityInterface $entity) { function hook_ENTITY_TYPE_presave(Drupal\Core\Entity\EntityInterface $entity) {
if ($entity->isTranslatable()) { if ($entity->isTranslatable()) {
$attributes = \Drupal::request()->attributes; $route_match = \Drupal::routeMatch();
\Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()->getId(), $attributes->get('source_langcode')); \Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()->getId(), $route_match->getParameter('source_langcode'));
} }
} }
......
...@@ -14,10 +14,12 @@ ...@@ -14,10 +14,12 @@
use Drupal\Core\Link; use Drupal\Core\Link;
use Drupal\Core\ParamConverter\ParamNotConvertedException; use Drupal\Core\ParamConverter\ParamNotConvertedException;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface; use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
...@@ -139,9 +141,10 @@ public function build(RouteMatchInterface $route_match) { ...@@ -139,9 +141,10 @@ public function build(RouteMatchInterface $route_match) {
// Copy the path elements for up-casting. // Copy the path elements for up-casting.
$route_request = $this->getRequestForPath(implode('/', $path_elements), $exclude); $route_request = $this->getRequestForPath(implode('/', $path_elements), $exclude);
if ($route_request) { if ($route_request) {
$access = $this->accessManager->checkRequest($route_request, $this->currentUser); $route_match = RouteMatch::createFromRequest($route_request);
$access = $this->accessManager->check($route_match, $this->currentUser);