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:
- [fromRequestStack, ['@request_stack']]
router.admin_context:
class: Drupal\Core\Routing\AdminContext
arguments: ['@request_stack']
arguments: ['@current_route_match']
router.route_provider:
class: Drupal\Core\Routing\RouteProvider
arguments: ['@database', '@router.builder', '@state']
......
......@@ -138,11 +138,15 @@ protected function createController($controller) {
*/
protected function doGetArguments(Request $request, $controller, array $parameters) {
$attributes = $request->attributes->all();
$raw_parameters = $request->attributes->has('_raw_variables') ? $request->attributes->get('_raw_variables') : [];
$arguments = array();
foreach ($parameters as $param) {
if (array_key_exists($param->name, $attributes)) {
$arguments[] = $attributes[$param->name];
}
elseif (array_key_exists($param->name, $raw_parameters)) {
$arguments[] = $attributes[$param->name];
}
elseif ($param->getClass() && $param->getClass()->isInstance($request)) {
$arguments[] = $request;
}
......@@ -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));
}
}
// 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;
}
......
......@@ -53,6 +53,13 @@ abstract class FormBase implements FormInterface, ContainerInjectionInterface {
*/
protected $loggerFactory;
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* {@inheritdoc}
*/
......@@ -135,6 +142,18 @@ protected function getRequest() {
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.
*
......
......@@ -7,8 +7,6 @@
namespace Drupal\Core\Routing;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Route;
/**
......@@ -17,20 +15,20 @@
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.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack used to determine the current request.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*/
public function __construct(RequestStack $request_stack) {
$this->requestStack = $request_stack;
public function __construct(RouteMatchInterface $route_match) {
$this->routeMatch = $route_match;
}
/**
......@@ -45,7 +43,7 @@ public function __construct(RequestStack $request_stack) {
*/
public function isAdminRoute(Route $route = NULL) {
if (!$route) {
$route = $this->getRouteFromRequest();
$route = $this->routeMatch->getRouteObject();
if (!$route) {
return FALSE;
}
......@@ -53,17 +51,4 @@ public function isAdminRoute(Route $route = NULL) {
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() {
return $this->getRouteMatch($this->requestStack->getParentRequest());
}
/**
* {@inheritdoc}
*/
public function getRouteMatchFromRequest(Request $request) {
return $this->getRouteMatch($request);
}
}
......@@ -7,6 +7,8 @@
namespace Drupal\Core\Routing;
use Symfony\Component\HttpFoundation\Request;
/**
* Defines an interface for a stack of route matches.
*
......@@ -36,5 +38,15 @@ public function getMasterRouteMatch();
*/
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)
* 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) {
$request = \Drupal::request();
if ($form_state->get('entity_type_id') == 'comment' && $request->attributes->has('commented_entity_type')) {
$form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($request->attributes->get('commented_entity_type'), $request->attributes->get('field_name'));
$route_match = \Drupal::routeMatch();
if ($form_state->get('entity_type_id') == 'comment' && $route_match->getParameter('commented_entity_type')) {
$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'))) {
// 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
* Implements hook_form_FORM_ID_alter().
*/
function comment_form_field_ui_form_display_overview_form_alter(&$form, FormStateInterface $form_state) {
$request = \Drupal::request();
if ($form['#entity_type'] == 'comment' && $request->attributes->has('commented_entity_type')) {
$form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($request->attributes->get('commented_entity_type'), $request->attributes->get('field_name'));
$route_match = \Drupal::routeMatch();
if ($form['#entity_type'] == 'comment' && $route_match->getParameter('commented_entity_type')) {
$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
* Implements hook_form_FORM_ID_alter().
*/
function comment_form_field_ui_display_overview_form_alter(&$form, FormStateInterface $form_state) {
$request = \Drupal::request();
if ($form['#entity_type'] == 'comment' && $request->attributes->has('commented_entity_type')) {
$form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($request->attributes->get('commented_entity_type'), $request->attributes->get('field_name'));
$route_match = \Drupal::routeMatch();
if ($form['#entity_type'] == 'comment' && $route_match->getParameter('commented_entity_type')) {
$form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($route_match->getParameter('commented_entity_type'), $route_match->getParameter('field_name'));
}
}
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url;
......
......@@ -281,6 +281,8 @@ public function hasTranslation(LanguageInterface $language);
/**
* Populate the config mapper with request data.
*
* @todo Replace $request with RouteMatch https://www.drupal.org/node/2295255.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* Page request object.
*/
......
......@@ -10,8 +10,8 @@
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
/**
* Base class for entity translation controllers.
......@@ -37,16 +37,15 @@ public function prepareTranslation(ContentEntityInterface $entity, LanguageInter
/**
* Builds the translations overview page.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object from which to extract the entity type.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @param string $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) {
$entity = $request->attributes->get($entity_type_id);
public function overview(RouteMatchInterface $route_match, $entity_type_id = NULL) {
$entity = $route_match->getParameter($entity_type_id);
$account = $this->currentUser();
$handler = $this->entityManager()->getHandler($entity_type_id, 'translation');
......@@ -252,16 +251,16 @@ public function overview(Request $request, $entity_type_id = NULL) {
* @param \Drupal\Core\Language\LanguageInterface $target
* The language of the translated values. Defaults to the current content
* language.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object from which to extract the entity type.
* @param \Drupal\Core\Routing\RouteMatchInterface
* The route match object from which to extract the entity type.
* @param string $entity_type_id
* (optional) The entity type ID.
*
* @return array
* A processed form array ready to be rendered.
*/
public function add(LanguageInterface $source, LanguageInterface $target, Request $request, $entity_type_id = NULL) {
$entity = $request->attributes->get($entity_type_id);
public function add(LanguageInterface $source, LanguageInterface $target, RouteMatchInterface $route_match, $entity_type_id = NULL) {
$entity = $route_match->getParameter($entity_type_id);
// @todo Exploit the upcoming hook_entity_prepare() when available.
// See https://www.drupal.org/node/1810394.
......@@ -287,16 +286,16 @@ public function add(LanguageInterface $source, LanguageInterface $target, Reques
* @param \Drupal\Core\Language\LanguageInterface $language
* The language of the translated values. Defaults to the current content
* language.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object from which to extract the entity type.
* @param \Drupal\Core\Routing\RouteMatchInterface
* The route match object from which to extract the entity type.
* @param string $entity_type_id
* (optional) The entity type ID.
*
* @return array
* A processed form array ready to be rendered.
*/
public function edit(LanguageInterface $language, Request $request, $entity_type_id = NULL) {
$entity = $request->attributes->get($entity_type_id);
public function edit(LanguageInterface $language, RouteMatchInterface $route_match, $entity_type_id = NULL) {
$entity = $route_match->getParameter($entity_type_id);
// @todo Provide a way to figure out the default form operation. Maybe like
// $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default';
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
/**
......@@ -40,9 +41,9 @@ public function getFormId() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $language = NULL) {
$this->entity = $this->getRequest()->attributes->get($entity_type_id);
$this->language = language_load($language);
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, LanguageInterface $language = NULL) {
$this->entity = $this->getRouteMatch()->getParameter($entity_type_id);
$this->language = $language;
return parent::buildForm($form, $form_state);
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\field_ui\Controller;
use Drupal\Core\Entity\Controller\EntityListController;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -22,18 +23,18 @@ class FieldConfigListController extends EntityListController {
* The entity type.
* @param string $bundle
* The entity bundle.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*
* @return array
* 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) {
$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
$form_state->set('entity_type_id', $entity_type_id);
}
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);
}
......
......@@ -7,9 +7,11 @@
namespace Drupal\node\Plugin\views\argument_default;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\views\Plugin\CacheablePluginInterface;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Default argument plugin to extract a node.
......@@ -23,11 +25,49 @@
*/
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}
*/
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();
}
}
......
......@@ -31,11 +31,13 @@ class RequestHandler implements ContainerAwareInterface {
* The route match.
* @param \Symfony\Component\HttpFoundation\Request $request
* The HTTP request object.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*
* @return \Symfony\Component\HttpFoundation\Response
* 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');
$method = strtolower($request->getMethod());
......@@ -76,7 +78,7 @@ public function handle(RouteMatchInterface $route_match, Request $request) {
// Determine the request parameters that should be passed to the resource
// plugin.
$route_parameters = $request->attributes->get('_route_params');
$route_parameters = $route_match->getParameters();
$parameters = array();
// Filter out all internal parameters starting with "_".
foreach ($route_parameters as $key => $parameter) {
......
......@@ -893,8 +893,8 @@ function hook_ENTITY_TYPE_storage_load(array $entities) {
*/
function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
if ($entity instanceof ContentEntityInterface && $entity->isTranslatable()) {
$attributes = \Drupal::request()->attributes;
\Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()->getId(), $attributes->get('source_langcode'));
$route_match = \Drupal::routeMatch();
\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) {
*/
function hook_ENTITY_TYPE_presave(Drupal\Core\Entity\EntityInterface $entity) {
if ($entity->isTranslatable()) {
$attributes = \Drupal::request()->attributes;
\Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()->getId(), $attributes->get('source_langcode'));
$route_match = \Drupal::routeMatch();
\Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()->getId(), $route_match->getParameter('source_langcode'));
}
}
......
......@@ -14,10 +14,12 @@
use Drupal\Core\Link;
use Drupal\Core\ParamConverter\ParamNotConvertedException;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
......@@ -139,9 +141,10 @@ public function build(RouteMatchInterface $route_match) {
// Copy the path elements for up-casting.
$route_request = $this->getRequestForPath(implode('/', $path_elements), $exclude);
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);
if ($access) {
$title = $this->titleResolver->getTitle($route_request, $route_request->attributes->get(RouteObjectInterface::ROUTE_OBJECT));
$title = $this->titleResolver->getTitle($route_request, $route_match->getRouteObject());
}
if ($access) {
if (!isset($title)) {
......@@ -149,7 +152,8 @@ public function build(RouteMatchInterface $route_match) {
// route is missing a _title or _title_callback attribute.
$title = str_replace(array('-', '_'), ' ', Unicode::ucfirst(end($path_elements)));
}
$links[] = Link::createFromRoute($title, $route_request->attributes->get(RouteObjectInterface::ROUTE_NAME), $route_request->attributes->get('_raw_variables')->all());
$url = Url::fromRouteMatch($route_match);
$links[] = new Link($title, $url);
}
}
......
......@@ -10,8 +10,8 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Controller routines for entity_test routes.
......@@ -65,8 +65,8 @@ public function testAdd($entity_type_id) {
/**
* Displays the 'Edit existing entity_test' form.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object to get entity type from.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match object to get entity type from.
* @param string $entity_type_id
* The entity type ID.
*
......@@ -75,8 +75,8 @@ public function testAdd($entity_type_id) {
*
* @see \Drupal\entity_test\Routing\EntityTestRoutes::routes()
*/
public function testEdit(Request $request, $entity_type_id) {
$entity = $request->attributes->get($entity_type_id);
public function testEdit(RouteMatchInterface $route_match, $entity_type_id) {
$entity = $route_match->getParameter($entity_type_id);
$form = $this->entityFormBuilder()->getForm($entity);
$form['#title'] = $entity->label();
return $form;
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a test form object.
......@@ -34,11 +35,11 @@ public static function create(ContainerInterface $container) {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $custom_attributes = NULL) {
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL, $custom_attributes = NULL) {
$form['element'] = array('#markup' => 'The FormTestControllerObject::buildForm() method was used for this form.');
$form['custom_attribute']['#markup'] = $custom_attributes;
$form['request_attribute']['#markup'] = $this->getRequest()->attributes->get('request_attribute');
$form['request_attribute']['#markup'] = $request->attributes->get('request_attribute');
$form['bananas'] = array(
'#type' => 'textfield',
......
......@@ -9,15 +9,13 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\NodeInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Controller routine for testing the paramconverter.
*/
class TestControllers {
public function testUserNodeFoo(EntityInterface $user, NodeInterface $node, Request $request) {
$foo = $request->attributes->get('foo');
public function testUserNodeFoo(EntityInterface $user, NodeInterface $node, $foo) {
$foo = is_object($foo) ? $foo->label() : $foo;
return ['#markup' => "user: {$user->label()}, node: {$node->label()}, foo: $foo"];
}
......
......@@ -326,8 +326,8 @@ public function testBuildWithUserPath() {
*/
public function setupAccessManagerToAllow() {
$this->accessManager->expects($this->any())
->method('checkRequest')
->will($this->returnValue(AccessResult::allowed()));
->method('check')
->willReturn(TRUE);
}
protected function setupStubPathProcessor() {
......
......@@ -8,6 +8,7 @@
namespace Drupal\taxonomy\Plugin\views\argument_default;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\taxonomy\TermInterface;
use Drupal\views\Plugin\CacheablePluginInterface;
use Drupal\views\ViewExecutable;
......@@ -27,6 +28,44 @@
*/
class Tid 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')
);
}
/**
* Overrides \Drupal\views\Plugin\views\Plugin\views\PluginBase::init().
*/
......@@ -126,14 +165,14 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state, &$opti
public function getArgument() {
// Load default argument from taxonomy page.
if (!empty($this->options['term_page'])) {
if (($taxonomy_term = $this->view->getRequest()->attributes->get('taxonomy_term')) && $taxonomy_term instanceof TermInterface) {
if (($taxonomy_term = $this->routeMatch->getParameter('taxonomy_term')) && $taxonomy_term instanceof TermInterface) {
return $taxonomy_term->id();
}
}
// Load default argument from node.
if (!empty($this->options['node'])) {
// Just check, if a node could be detected.
if (($node = $this->view->getRequest()->attributes->get('node')) && $node instanceof NodeInterface) {
if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
$taxonomy = array();
foreach ($node->getFieldDefinitions() as $field) {
if ($field->getType() == 'taxonomy_term_reference') {
......
......@@ -119,7 +119,8 @@ function update_help($route_name, RouteMatchInterface $route_match) {
function update_page_top() {
/** @var \Drupal\Core\Routing\AdminContext $admin_context */
$admin_context = \Drupal::service('router.admin_context');
if ($admin_context->isAdminRoute(\Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) && \Drupal::currentUser()->hasPermission('administer site configuration')) {
$route_match = \Drupal::routeMatch();
if ($admin_context->isAdminRoute($route_match->getRouteObject()) && \Drupal::currentUser()->hasPermission('administer site configuration')) {
$route_name = \Drupal::routeMatch()->getRouteName();
switch ($route_name) {
// These pages don't need additional nagging.
......