diff --git a/core/modules/comment/src/Plugin/views/field/Link.php b/core/modules/comment/src/Plugin/views/field/Link.php index 70c5c0e..a06c00a 100644 --- a/core/modules/comment/src/Plugin/views/field/Link.php +++ b/core/modules/comment/src/Plugin/views/field/Link.php @@ -11,6 +11,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Routing\RedirectDestinationInterface; use Drupal\Core\Url; use Drupal\views\ResultRow; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -32,6 +33,14 @@ class Link extends FieldPluginBase { protected $entityManager; /** + * The redirect destination service. + * + * @var \Drupal\Core\Routing\RedirectDestinationInterface + */ + + protected $redirectDestination; + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { @@ -39,7 +48,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('entity.manager') + $container->get('entity.manager'), + $container->get('redirect.destination') ); } @@ -54,10 +64,13 @@ public static function create(ContainerInterface $container, array $configuratio * The plugin implementation definition. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. + * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination + * The redirect destination service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, RedirectDestinationInterface $redirect_destination) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityManager = $entity_manager; + $this->redirectDestination = $redirect_destination; } /** diff --git a/core/modules/comment/src/Plugin/views/field/LinkApprove.php b/core/modules/comment/src/Plugin/views/field/LinkApprove.php index 5d152f2..fabcb74 100644 --- a/core/modules/comment/src/Plugin/views/field/LinkApprove.php +++ b/core/modules/comment/src/Plugin/views/field/LinkApprove.php @@ -53,7 +53,7 @@ protected function renderLink($data, ResultRow $values) { $this->options['alter']['make_link'] = TRUE; $this->options['alter']['url'] = Url::fromRoute('comment.approve', ['comment' => $comment->id()]); - $this->options['alter']['query'] = \Drupal::service('redirect.destination')->getAsArray() + array('token' => \Drupal::csrfToken()->get($this->options['alter']['url']->toString())); + $this->options['alter']['query'] = $this->redirectDestination->getAsArray() + array('token' => \Drupal::csrfToken()->get($this->options['alter']['url']->toString())); return $text; } diff --git a/core/modules/comment/src/Plugin/views/field/LinkDelete.php b/core/modules/comment/src/Plugin/views/field/LinkDelete.php index c504e65..fb723ed 100644 --- a/core/modules/comment/src/Plugin/views/field/LinkDelete.php +++ b/core/modules/comment/src/Plugin/views/field/LinkDelete.php @@ -44,7 +44,7 @@ protected function renderLink($data, ResultRow $values) { $this->options['alter']['make_link'] = TRUE; $this->options['alter']['url'] = $comment->urlInfo('delete-form'); - $this->options['alter']['query'] = \Drupal::service('redirect.destination')->getAsArray(); + $this->options['alter']['query'] = $this->redirectDestination->getAsArray(); return $text; } diff --git a/core/modules/comment/src/Plugin/views/field/LinkEdit.php b/core/modules/comment/src/Plugin/views/field/LinkEdit.php index 6d411a3..11f8909 100644 --- a/core/modules/comment/src/Plugin/views/field/LinkEdit.php +++ b/core/modules/comment/src/Plugin/views/field/LinkEdit.php @@ -60,7 +60,7 @@ protected function renderLink($data, ResultRow $values) { unset($this->options['alter']['fragment']); if (!empty($this->options['destination'])) { - $this->options['alter']['query'] = \Drupal::service('redirect.destination')->getAsArray(); + $this->options['alter']['query'] = $this->redirectDestination->getAsArray(); } $this->options['alter']['url'] = $comment->urlInfo('edit-form'); diff --git a/core/modules/contextual/src/Plugin/views/field/ContextualLinks.php b/core/modules/contextual/src/Plugin/views/field/ContextualLinks.php index 5a71c70..a025827 100644 --- a/core/modules/contextual/src/Plugin/views/field/ContextualLinks.php +++ b/core/modules/contextual/src/Plugin/views/field/ContextualLinks.php @@ -11,6 +11,7 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\RedirectDestinationInterface; use Drupal\Core\Url; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\ResultRow; @@ -25,6 +26,31 @@ class ContextualLinks extends FieldPluginBase { /** + * The redirect destination service. + * + * @var \Drupal\Core\Routing\RedirectDestinationInterface + */ + + protected $redirectDestination; + + /** + * Constructs a Link field plugin. + * + * @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\RedirectDestinationInterface $redirect_destination + * The redirect destination service. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, RedirectDestinationInterface $redirect_destination) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->redirectDestination = $redirect_destination; + } + + /** * {@inheritdoc} */ public function usesGroupBy() { @@ -119,7 +145,7 @@ public function render(ResultRow $values) { 'title' => $title, ); if (!empty($this->options['destination'])) { - $links[$field]['query'] = \Drupal::service('redirect.destination')->getAsArray(); + $links[$field]['query'] = $this->redirectDestination->getAsArray(); } } } diff --git a/core/modules/node/src/Plugin/views/field/LinkDelete.php b/core/modules/node/src/Plugin/views/field/LinkDelete.php index cc4582e..2737ea7 100644 --- a/core/modules/node/src/Plugin/views/field/LinkDelete.php +++ b/core/modules/node/src/Plugin/views/field/LinkDelete.php @@ -38,7 +38,7 @@ protected function renderLink($node, ResultRow $values) { $this->options['alter']['make_link'] = TRUE; $this->options['alter']['url'] = $node->urlInfo('delete-form'); - $this->options['alter']['query'] = \Drupal::service('redirect.destination')->getAsArray(); + $this->options['alter']['query'] = $this->redirectDestination->getAsArray(); $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Delete'); return $text; diff --git a/core/modules/node/src/Plugin/views/field/LinkEdit.php b/core/modules/node/src/Plugin/views/field/LinkEdit.php index 750cd53..279dcd0 100644 --- a/core/modules/node/src/Plugin/views/field/LinkEdit.php +++ b/core/modules/node/src/Plugin/views/field/LinkEdit.php @@ -39,7 +39,7 @@ protected function renderLink($node, ResultRow $values) { $this->options['alter']['make_link'] = TRUE; $this->options['alter']['url'] = $node->urlInfo('edit-form'); - $this->options['alter']['query'] = \Drupal::service('redirect.destination')->getAsArray(); + $this->options['alter']['query'] = $this->redirectDestination->getAsArray(); $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Edit'); return $text; diff --git a/core/modules/node/src/Plugin/views/field/RevisionLink.php b/core/modules/node/src/Plugin/views/field/RevisionLink.php index d2b6f68..5c7c4dc 100644 --- a/core/modules/node/src/Plugin/views/field/RevisionLink.php +++ b/core/modules/node/src/Plugin/views/field/RevisionLink.php @@ -66,7 +66,7 @@ protected function renderLink($data, ResultRow $values) { $this->options['alter']['make_link'] = TRUE; $this->options['alter']['url'] = $url; - $this->options['alter']['query'] = \Drupal::service('redirect.destination')->getAsArray(); + $this->options['alter']['query'] = $this->redirectDestination->getAsArray(); return !empty($this->options['text']) ? $this->options['text'] : $this->t('View'); } diff --git a/core/modules/node/src/Plugin/views/field/RevisionLinkDelete.php b/core/modules/node/src/Plugin/views/field/RevisionLinkDelete.php index 2dc352c..773e764 100644 --- a/core/modules/node/src/Plugin/views/field/RevisionLinkDelete.php +++ b/core/modules/node/src/Plugin/views/field/RevisionLinkDelete.php @@ -52,7 +52,7 @@ protected function renderLink($data, ResultRow $values) { $this->options['alter']['make_link'] = TRUE; $this->options['alter']['url'] = Url::fromRoute('node.revision_delete_confirm', ['node' => $node->id(), 'node_revision' => $vid]); - $this->options['alter']['query'] = \Drupal::service('redirect.destination')->getAsArray(); + $this->options['alter']['query'] = $this->redirectDestination->getAsArray(); return !empty($this->options['text']) ? $this->options['text'] : $this->t('Delete'); } diff --git a/core/modules/node/src/Plugin/views/field/RevisionLinkRevert.php b/core/modules/node/src/Plugin/views/field/RevisionLinkRevert.php index d3ada26..163d636 100644 --- a/core/modules/node/src/Plugin/views/field/RevisionLinkRevert.php +++ b/core/modules/node/src/Plugin/views/field/RevisionLinkRevert.php @@ -52,7 +52,7 @@ protected function renderLink($data, ResultRow $values) { $this->options['alter']['make_link'] = TRUE; $this->options['alter']['url'] = Url::fromRoute('node.revision_revert_confirm', ['node' => $node->id(), 'node_revision' => $vid]); - $this->options['alter']['query'] = \Drupal::service('redirect.destination')->getAsArray(); + $this->options['alter']['query'] = $this->redirectDestination->getAsArray(); return !empty($this->options['text']) ? $this->options['text'] : $this->t('Revert'); } diff --git a/core/modules/taxonomy/src/Plugin/views/field/LinkEdit.php b/core/modules/taxonomy/src/Plugin/views/field/LinkEdit.php index 70465d2..5aa2396 100644 --- a/core/modules/taxonomy/src/Plugin/views/field/LinkEdit.php +++ b/core/modules/taxonomy/src/Plugin/views/field/LinkEdit.php @@ -8,6 +8,7 @@ namespace Drupal\taxonomy\Plugin\views\field; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\RedirectDestinationInterface; use Drupal\Core\Url; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; @@ -24,6 +25,42 @@ class LinkEdit extends FieldPluginBase { /** + * The redirect destination service. + * + * @var \Drupal\Core\Routing\RedirectDestinationInterface + */ + protected $redirectDestination; + + /** + * Constructs a Link field plugin. + * + * @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\RedirectDestinationInterface $redirect_destination + * The redirect destination service. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, RedirectDestinationInterface $redirect_destination) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->redirectDestination = $redirect_destination; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('redirect.destination') + ); + } + + /** * {@inheritdoc} */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { @@ -78,7 +115,7 @@ public function render(ResultRow $values) { )); if ($term->access('update')) { $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Edit'); - return \Drupal::l($text, new Url('entity.taxonomy.edit_form', ['taxonomy_term' => $tid], array('query' => \Drupal::service('redirect.destination')->getAsArray()))); + return \Drupal::l($text, new Url('entity.taxonomy.edit_form', ['taxonomy_term' => $tid], array('query' => $this->redirectDestination->getAsArray()))); } } } diff --git a/core/modules/user/src/Plugin/views/field/Link.php b/core/modules/user/src/Plugin/views/field/Link.php index f5ef6bd..ca3a7bf 100644 --- a/core/modules/user/src/Plugin/views/field/Link.php +++ b/core/modules/user/src/Plugin/views/field/Link.php @@ -8,6 +8,7 @@ namespace Drupal\user\Plugin\views\field; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\RedirectDestinationInterface; use Drupal\Core\Session\AccountInterface; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; @@ -25,6 +26,43 @@ class Link extends FieldPluginBase { /** + * The redirect destination service. + * + * @var \Drupal\Core\Routing\RedirectDestinationInterface + */ + + protected $redirectDestination; + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('redirect.destination') + ); + } + + /** + * Constructs a Link field plugin. + * + * @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\RedirectDestinationInterface $redirect_destination + * The redirect destination service. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, RedirectDestinationInterface $redirect_destination) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->redirectDestination = $redirect_destination; + } + + /** * {@inheritdoc} */ public function usesGroupBy() { diff --git a/core/modules/user/src/Plugin/views/field/LinkCancel.php b/core/modules/user/src/Plugin/views/field/LinkCancel.php index c63e00e..d41f179 100644 --- a/core/modules/user/src/Plugin/views/field/LinkCancel.php +++ b/core/modules/user/src/Plugin/views/field/LinkCancel.php @@ -29,7 +29,7 @@ protected function renderLink(EntityInterface $entity, ResultRow $values) { $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Cancel account'); $this->options['alter']['url'] = $entity->urlInfo('cancel-form'); - $this->options['alter']['query'] = \Drupal::service('redirect.destination')->getAsArray(); + $this->options['alter']['query'] = $this->redirectDestination->getAsArray(); return $text; } diff --git a/core/modules/user/src/Plugin/views/field/LinkEdit.php b/core/modules/user/src/Plugin/views/field/LinkEdit.php index e0fbf60..b2c9215 100644 --- a/core/modules/user/src/Plugin/views/field/LinkEdit.php +++ b/core/modules/user/src/Plugin/views/field/LinkEdit.php @@ -28,7 +28,7 @@ protected function renderLink(EntityInterface $entity, ResultRow $values) { $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Edit'); - $this->options['alter']['url'] = $entity->urlInfo('edit-form', ['query' => ['destination' => \Drupal::service('redirect.destination')->getAsArray()]]); + $this->options['alter']['url'] = $entity->urlInfo('edit-form', ['query' => ['destination' => $this->redirectDestination->getAsArray()]]); return $text; } diff --git a/core/modules/views/src/Plugin/views/field/Links.php b/core/modules/views/src/Plugin/views/field/Links.php index d54d566..bff3f0a 100644 --- a/core/modules/views/src/Plugin/views/field/Links.php +++ b/core/modules/views/src/Plugin/views/field/Links.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\RedirectDestinationInterface; use Drupal\Core\Url as UrlObject; /** @@ -18,6 +19,43 @@ */ abstract class Links extends FieldPluginBase { + /** + * The redirect destination service. + * + * @var \Drupal\Core\Routing\RedirectDestinationInterface + */ + + protected $redirectDestination; + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('redirect.destination') + ); + } + + /** + * Constructs a Link field plugin. + * + * @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\RedirectDestinationInterface $redirect_destination + * The redirect destination service. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, RedirectDestinationInterface $redirect_destination) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->redirectDestination = $redirect_destination; + } + /** * {@inheritdoc} */ @@ -89,7 +127,7 @@ protected function getLinks() { 'title' => $title, ); if (!empty($this->options['destination'])) { - $links[$field]['query'] = \Drupal::service('redirect.destination')->getAsArray(); + $links[$field]['query'] = $this->redirectDestination->getAsArray(); } }