Issue #2448605 by martin107, willzyx, tim.plunkett, klausi, dpopdan: Replace usages of drupal_get_destination() with the redirect destination service
parent
6ffc4cd8ba
commit
d48d9c9271
|
@ -989,7 +989,7 @@ services:
|
|||
class: Drupal\Core\EventSubscriber\DefaultExceptionHtmlSubscriber
|
||||
tags:
|
||||
- { name: event_subscriber }
|
||||
arguments: ['@http_kernel', '@logger.channel.php']
|
||||
arguments: ['@http_kernel', '@logger.channel.php', '@redirect.destination']
|
||||
exception.default:
|
||||
class: Drupal\Core\EventSubscriber\DefaultExceptionSubscriber
|
||||
tags:
|
||||
|
@ -1009,7 +1009,7 @@ services:
|
|||
class: Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber
|
||||
tags:
|
||||
- { name: event_subscriber }
|
||||
arguments: ['@config.factory', '@path.alias_manager', '@http_kernel', '@logger.channel.php']
|
||||
arguments: ['@config.factory', '@path.alias_manager', '@http_kernel', '@logger.channel.php', '@redirect.destination']
|
||||
exception.fast_404_html:
|
||||
class: Drupal\Core\EventSubscriber\Fast404ExceptionHtmlSubscriber
|
||||
tags:
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Drupal\Core\Controller;
|
|||
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\Routing\LinkGeneratorTrait;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
use Drupal\Core\Routing\UrlGeneratorTrait;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
@ -35,8 +36,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
* @ingroup menu
|
||||
*/
|
||||
abstract class ControllerBase implements ContainerInjectionInterface {
|
||||
use StringTranslationTrait;
|
||||
|
||||
use LinkGeneratorTrait;
|
||||
use RedirectDestinationTrait;
|
||||
use StringTranslationTrait;
|
||||
use UrlGeneratorTrait;
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Drupal\Core\EventSubscriber;
|
|||
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Path\AliasManagerInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||
|
@ -44,9 +45,11 @@ class CustomPageExceptionHtmlSubscriber extends DefaultExceptionHtmlSubscriber {
|
|||
* The HTTP Kernel service.
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* The logger service.
|
||||
* @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
|
||||
* The redirect destination service.
|
||||
*/
|
||||
public function __construct(ConfigFactoryInterface $config_factory, AliasManagerInterface $alias_manager, HttpKernelInterface $http_kernel, LoggerInterface $logger) {
|
||||
parent::__construct($http_kernel, $logger);
|
||||
public function __construct(ConfigFactoryInterface $config_factory, AliasManagerInterface $alias_manager, HttpKernelInterface $http_kernel, LoggerInterface $logger, RedirectDestinationInterface $redirect_destination) {
|
||||
parent::__construct($http_kernel, $logger, $redirect_destination);
|
||||
$this->configFactory = $config_factory;
|
||||
$this->aliasManager = $alias_manager;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\Core\EventSubscriber;
|
||||
|
||||
use Drupal\Core\Routing\AccessAwareRouterInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Utility\Error;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
@ -35,6 +36,13 @@ class DefaultExceptionHtmlSubscriber extends HttpExceptionSubscriberBase {
|
|||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* The redirect destination service.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\RedirectDestinationInterface
|
||||
*/
|
||||
protected $redirectDestination;
|
||||
|
||||
/**
|
||||
* Constructs a new DefaultExceptionHtmlSubscriber.
|
||||
*
|
||||
|
@ -42,10 +50,13 @@ class DefaultExceptionHtmlSubscriber extends HttpExceptionSubscriberBase {
|
|||
* The HTTP kernel.
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* The logger service.
|
||||
* @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
|
||||
* The redirect destination service.
|
||||
*/
|
||||
public function __construct(HttpKernelInterface $http_kernel, LoggerInterface $logger) {
|
||||
public function __construct(HttpKernelInterface $http_kernel, LoggerInterface $logger, RedirectDestinationInterface $redirect_destination) {
|
||||
$this->httpKernel = $http_kernel;
|
||||
$this->logger = $logger;
|
||||
$this->redirectDestination = $redirect_destination;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,10 +116,10 @@ class DefaultExceptionHtmlSubscriber extends HttpExceptionSubscriberBase {
|
|||
|
||||
if ($url != $request->getBasePath() . '/' && $url != $current_url) {
|
||||
if ($request->getMethod() === 'POST') {
|
||||
$sub_request = Request::create($url, 'POST', $this->drupalGetDestination() + ['_exception_statuscode' => $status_code] + $request->request->all(), $request->cookies->all(), [], $request->server->all());
|
||||
$sub_request = Request::create($url, 'POST', $this->redirectDestination->getAsArray() + ['_exception_statuscode' => $status_code] + $request->request->all(), $request->cookies->all(), [], $request->server->all());
|
||||
}
|
||||
else {
|
||||
$sub_request = Request::create($url, 'GET', $request->query->all() + $this->drupalGetDestination() + ['_exception_statuscode' => $status_code], $request->cookies->all(), [], $request->server->all());
|
||||
$sub_request = Request::create($url, 'GET', $request->query->all() + $this->redirectDestination->getAsArray() + ['_exception_statuscode' => $status_code], $request->cookies->all(), [], $request->server->all());
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -137,11 +148,4 @@ class DefaultExceptionHtmlSubscriber extends HttpExceptionSubscriberBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps drupal_get_destination().
|
||||
*/
|
||||
protected function drupalGetDestination() {
|
||||
return drupal_get_destination();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use Drupal\Core\Config\ConfigFactoryInterface;
|
|||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
|
||||
use Drupal\Core\Routing\LinkGeneratorTrait;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
use Drupal\Core\Routing\UrlGeneratorTrait;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
@ -22,9 +23,11 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
|||
* @ingroup form_api
|
||||
*/
|
||||
abstract class FormBase implements FormInterface, ContainerInjectionInterface {
|
||||
use StringTranslationTrait;
|
||||
|
||||
use DependencySerializationTrait;
|
||||
use LinkGeneratorTrait;
|
||||
use RedirectDestinationTrait;
|
||||
use StringTranslationTrait;
|
||||
use UrlGeneratorTrait;
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,7 +63,7 @@ class SystemCompactLink extends Link {
|
|||
$element['#url'] = BaseUrl::fromRoute('system.admin_compact_page', array('mode' => 'off'));
|
||||
$element['#options'] = array(
|
||||
'attributes' => array('title' => t('Expand layout to include descriptions.')),
|
||||
'query' => drupal_get_destination(),
|
||||
'query' => \Drupal::destination()->getAsArray()
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
@ -71,7 +71,7 @@ class SystemCompactLink extends Link {
|
|||
$element['#url'] = BaseUrl::fromRoute('system.admin_compact_page', array('mode' => 'on'));
|
||||
$element['#options'] = array(
|
||||
'attributes' => array('title' => t('Compress layout by hiding descriptions.')),
|
||||
'query' => drupal_get_destination(),
|
||||
'query' => \Drupal::destination()->getAsArray(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains Drupal\Core\Routing\RedirectDestinationTrait.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Routing;
|
||||
|
||||
/**
|
||||
* Wrapper methods for the Redirect Destination.
|
||||
*
|
||||
* This utility trait should only be used in application-level code, such as
|
||||
* classes that would implement ContainerInjectionInterface. Services registered
|
||||
* in the Container should not use this trait but inject the appropriate service
|
||||
* directly for easier testing.
|
||||
*/
|
||||
trait RedirectDestinationTrait {
|
||||
|
||||
/**
|
||||
* The redirect destination service.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\RedirectDestinationInterface
|
||||
*/
|
||||
protected $redirectDestination;
|
||||
|
||||
/**
|
||||
* Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
|
||||
*
|
||||
* @see \Drupal\Core\Routing\RedirectDestinationInterface::getAsArray()
|
||||
*
|
||||
* @return array
|
||||
* An associative array containing the key:
|
||||
* - destination: The value of the current request's 'destination' query
|
||||
* parameter, if present. This can be either a relative or absolute URL.
|
||||
* However, for security, redirection to external URLs is not performed.
|
||||
* If the query parameter isn't present, then the URL of the current
|
||||
* request is returned.
|
||||
*/
|
||||
protected function getDestinationArray() {
|
||||
return $this->getRedirectDestination()->getAsArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the redirect destination service.
|
||||
*
|
||||
* @return \Drupal\Core\Routing\RedirectDestinationInterface
|
||||
* The redirect destination helper.
|
||||
*/
|
||||
protected function getRedirectDestination() {
|
||||
if (!isset($this->redirectDestination)) {
|
||||
$this->redirectDestination = \Drupal::destination();
|
||||
}
|
||||
|
||||
return $this->redirectDestination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the redirect destination service.
|
||||
*
|
||||
* @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
|
||||
* The redirect destination service.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRedirectDestination(RedirectDestinationInterface $redirect_destination) {
|
||||
$this->redirectDestination = $redirect_destination;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
|
@ -206,7 +206,7 @@ class BookAdminEditForm extends FormBase {
|
|||
$delta = ($count < 30) ? 15 : intval($count / 2) + 1;
|
||||
|
||||
$access = \Drupal::currentUser()->hasPermission('administer nodes');
|
||||
$destination = drupal_get_destination();
|
||||
$destination = $this->getDestinationArray();
|
||||
|
||||
foreach ($tree as $data) {
|
||||
$nid = $data['link']['nid'];
|
||||
|
|
|
@ -159,7 +159,7 @@ class CommentManager implements CommentManagerInterface {
|
|||
}
|
||||
|
||||
if ($this->authenticatedCanPostComments) {
|
||||
// We cannot use drupal_get_destination() because these links
|
||||
// We cannot use the redirect.destination service here because these links
|
||||
// sometimes appear on /node and taxonomy listing pages.
|
||||
if ($entity->get($field_name)->getFieldDefinition()->getSetting('form_location') == CommentItemInterface::FORM_SEPARATE_PAGE) {
|
||||
$comment_reply_parameters = [
|
||||
|
|
|
@ -167,7 +167,7 @@ class CommentAdminOverview extends FormBase {
|
|||
|
||||
// Build a table listing the appropriate comments.
|
||||
$options = array();
|
||||
$destination = drupal_get_destination();
|
||||
$destination = $this->getDestinationArray();
|
||||
|
||||
$commented_entity_ids = array();
|
||||
$commented_entities = array();
|
||||
|
|
|
@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityManagerInterface;
|
|||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\views\Plugin\views\field\FieldPluginBase;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\views\ResultRow;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
@ -24,6 +25,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
*/
|
||||
class Link extends FieldPluginBase {
|
||||
|
||||
use RedirectDestinationTrait;
|
||||
|
||||
/**
|
||||
* Entity Manager service.
|
||||
*
|
||||
|
|
|
@ -53,7 +53,7 @@ class LinkApprove extends Link {
|
|||
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['url'] = Url::fromRoute('comment.approve', ['comment' => $comment->id()]);
|
||||
$this->options['alter']['query'] = drupal_get_destination() + array('token' => \Drupal::csrfToken()->get($this->options['alter']['url']->toString()));
|
||||
$this->options['alter']['query'] = $this->getDestinationArray() + array('token' => \Drupal::csrfToken()->get($this->options['alter']['url']->toString()));
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class LinkDelete extends Link {
|
|||
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['url'] = $comment->urlInfo('delete-form');
|
||||
$this->options['alter']['query'] = drupal_get_destination();
|
||||
$this->options['alter']['query'] = $this->getDestinationArray();
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ class LinkEdit extends Link {
|
|||
unset($this->options['alter']['fragment']);
|
||||
|
||||
if (!empty($this->options['destination'])) {
|
||||
$this->options['alter']['query'] = drupal_get_destination();
|
||||
$this->options['alter']['query'] = $this->getDestinationArray();
|
||||
}
|
||||
|
||||
$this->options['alter']['url'] = $comment->urlInfo('edit-form');
|
||||
|
|
|
@ -336,7 +336,7 @@ function content_translation_form_field_config_edit_form_alter(array &$form, For
|
|||
// Provide helpful pointers for administrators.
|
||||
if (\Drupal::currentUser()->hasPermission('administer content translation') && !$bundle_is_translatable) {
|
||||
$toggle_url = \Drupal::url('language.content_settings_page', array(), array(
|
||||
'query' => drupal_get_destination(),
|
||||
'query' => \Drupal::destination()->getAsArray(),
|
||||
));
|
||||
$form['translatable']['#description'] = t('To configure translation for this field, <a href="@language-settings-url">enable language support</a> for this type.', array(
|
||||
'@language-settings-url' => $toggle_url,
|
||||
|
|
|
@ -11,6 +11,7 @@ use Drupal\Component\Serialization\Json;
|
|||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\views\Plugin\views\field\FieldPluginBase;
|
||||
use Drupal\views\ResultRow;
|
||||
|
@ -24,6 +25,8 @@ use Drupal\views\ResultRow;
|
|||
*/
|
||||
class ContextualLinks extends FieldPluginBase {
|
||||
|
||||
use RedirectDestinationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -119,7 +122,7 @@ class ContextualLinks extends FieldPluginBase {
|
|||
'title' => $title,
|
||||
);
|
||||
if (!empty($this->options['destination'])) {
|
||||
$links[$field]['query'] = drupal_get_destination();
|
||||
$links[$field]['query'] = $this->getDestinationArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -417,7 +417,7 @@ class FieldStorageAddForm extends FormBase {
|
|||
}
|
||||
|
||||
if ($destinations) {
|
||||
$destination = drupal_get_destination();
|
||||
$destination = $this->getDestinationArray();
|
||||
$destinations[] = $destination['destination'];
|
||||
$form_state->setRedirectUrl(FieldUI::getNextDestination($destinations, $form_state));
|
||||
}
|
||||
|
|
|
@ -290,7 +290,7 @@ class ForumController extends ControllerBase {
|
|||
'#theme' => 'menu_local_action',
|
||||
'#link' => array(
|
||||
'title' => $this->t('Log in to post new content in the forum.'),
|
||||
'url' => Url::fromRoute('user.login', [], ['query' => $this->getDestination()]),
|
||||
'url' => Url::fromRoute('user.login', [], ['query' => $this->getDestinationArray()]),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
@ -298,11 +298,4 @@ class ForumController extends ControllerBase {
|
|||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps drupal_get_destination().
|
||||
*/
|
||||
protected function getDestination() {
|
||||
return drupal_get_destination();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -120,5 +120,5 @@ function template_preprocess_locale_translation_last_check(array &$variables) {
|
|||
$last = $variables['last'];
|
||||
$variables['last_checked'] = ($last != NULL);
|
||||
$variables['time'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $last);
|
||||
$variables['link'] = \Drupal::l(t('Check manually'), new Url('locale.check_translation', array(), array('query' => drupal_get_destination())));
|
||||
$variables['link'] = \Drupal::l(t('Check manually'), new Url('locale.check_translation', array(), array('query' => \Drupal::destination()->getAsArray())));
|
||||
}
|
||||
|
|
|
@ -383,7 +383,7 @@ class MenuForm extends EntityForm {
|
|||
if ($edit_route) {
|
||||
$operations['edit']['url'] = $edit_route;
|
||||
// Bring the user back to the menu overview.
|
||||
$operations['edit']['query'] = drupal_get_destination();
|
||||
$operations['edit']['query'] = $this->getDestinationArray();
|
||||
}
|
||||
else {
|
||||
// Fall back to the standard edit link.
|
||||
|
@ -400,7 +400,7 @@ class MenuForm extends EntityForm {
|
|||
}
|
||||
elseif ($delete_link = $link->getDeleteRoute()) {
|
||||
$operations['delete']['url'] = $delete_link;
|
||||
$operations['delete']['query'] = drupal_get_destination();
|
||||
$operations['delete']['query'] = $this->getDestinationArray();
|
||||
$operations['delete']['title'] = $this->t('Delete');
|
||||
}
|
||||
if ($link->isTranslatable()) {
|
||||
|
|
|
@ -14,6 +14,7 @@ use Drupal\Core\Entity\EntityListBuilder;
|
|||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
@ -30,6 +31,13 @@ class NodeListBuilder extends EntityListBuilder {
|
|||
*/
|
||||
protected $dateFormatter;
|
||||
|
||||
/**
|
||||
* The redirect destination service.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\RedirectDestinationInterface
|
||||
*/
|
||||
protected $redirectDestination;
|
||||
|
||||
/**
|
||||
* Constructs a new NodeListBuilder object.
|
||||
*
|
||||
|
@ -39,11 +47,14 @@ class NodeListBuilder extends EntityListBuilder {
|
|||
* The entity storage class.
|
||||
* @param \Drupal\Core\Datetime\DateFormatter $date_formatter
|
||||
* The date formatter service.
|
||||
* @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
|
||||
* The redirect destination service.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatter $date_formatter) {
|
||||
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatter $date_formatter, RedirectDestinationInterface $redirect_destination) {
|
||||
parent::__construct($entity_type, $storage);
|
||||
|
||||
$this->dateFormatter = $date_formatter;
|
||||
$this->redirectDestination = $redirect_destination;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +64,8 @@ class NodeListBuilder extends EntityListBuilder {
|
|||
return new static(
|
||||
$entity_type,
|
||||
$container->get('entity.manager')->getStorage($entity_type->id()),
|
||||
$container->get('date.formatter')
|
||||
$container->get('date.formatter'),
|
||||
$container->get('redirect.destination')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -128,7 +140,7 @@ class NodeListBuilder extends EntityListBuilder {
|
|||
protected function getDefaultOperations(EntityInterface $entity) {
|
||||
$operations = parent::getDefaultOperations($entity);
|
||||
|
||||
$destination = drupal_get_destination();
|
||||
$destination = $this->redirectDestination->getAsArray();
|
||||
foreach ($operations as $key => $operation) {
|
||||
$operations[$key]['query'] = $destination;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\node\Plugin\views\field;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
use Drupal\views\Plugin\views\field\FieldPluginBase;
|
||||
use Drupal\views\ResultRow;
|
||||
|
||||
|
@ -20,6 +21,8 @@ use Drupal\views\ResultRow;
|
|||
*/
|
||||
class Link extends FieldPluginBase {
|
||||
|
||||
use RedirectDestinationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -38,7 +38,7 @@ class LinkDelete extends Link {
|
|||
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['url'] = $node->urlInfo('delete-form');
|
||||
$this->options['alter']['query'] = drupal_get_destination();
|
||||
$this->options['alter']['query'] = $this->getDestinationArray();
|
||||
|
||||
$text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Delete');
|
||||
return $text;
|
||||
|
|
|
@ -39,7 +39,7 @@ class LinkEdit extends Link {
|
|||
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['url'] = $node->urlInfo('edit-form');
|
||||
$this->options['alter']['query'] = drupal_get_destination();
|
||||
$this->options['alter']['query'] = $this->getDestinationArray();
|
||||
|
||||
$text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Edit');
|
||||
return $text;
|
||||
|
|
|
@ -66,7 +66,7 @@ class RevisionLink extends Link {
|
|||
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['url'] = $url;
|
||||
$this->options['alter']['query'] = drupal_get_destination();
|
||||
$this->options['alter']['query'] = $this->getDestinationArray();
|
||||
|
||||
return !empty($this->options['text']) ? $this->options['text'] : $this->t('View');
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ class RevisionLinkDelete extends RevisionLink {
|
|||
|
||||
$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_get_destination();
|
||||
$this->options['alter']['query'] = $this->getDestinationArray();
|
||||
|
||||
return !empty($this->options['text']) ? $this->options['text'] : $this->t('Delete');
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ class RevisionLinkRevert extends RevisionLink {
|
|||
|
||||
$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_get_destination();
|
||||
$this->options['alter']['query'] = $this->getDestinationArray();
|
||||
|
||||
return !empty($this->options['text']) ? $this->options['text'] : $this->t('Revert');
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ class PathController extends ControllerBase {
|
|||
$header[] = $this->t('Operations');
|
||||
|
||||
$rows = array();
|
||||
$destination = drupal_get_destination();
|
||||
$destination = $this->getDestinationArray();
|
||||
foreach ($this->aliasStorage->getAliasesForAdminListing($header, $keys) as $data) {
|
||||
$row = array();
|
||||
// @todo Should Path module store leading slashes? See
|
||||
|
|
|
@ -58,7 +58,7 @@ class EditForm extends PathFormBase {
|
|||
));
|
||||
|
||||
if ($this->getRequest()->query->has('destination')) {
|
||||
$url->setOption('query', drupal_get_destination());
|
||||
$url->setOption('query', $this->getDestinationArray());
|
||||
$this->getRequest()->query->remove('destination');
|
||||
}
|
||||
|
||||
|
|
|
@ -313,7 +313,7 @@ function shortcut_preprocess_page(&$variables) {
|
|||
'link' => $link,
|
||||
'name' => $variables['title'],
|
||||
);
|
||||
$query += drupal_get_destination();
|
||||
$query += \Drupal::destination()->getAsArray();
|
||||
|
||||
$shortcut_set = shortcut_current_displayed_set();
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Drupal\system\Plugin\views\field;
|
|||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
use Drupal\views\Plugin\views\field\FieldPluginBase;
|
||||
use Drupal\views\Plugin\views\style\Table;
|
||||
|
@ -24,6 +25,8 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
|||
*/
|
||||
class BulkForm extends FieldPluginBase {
|
||||
|
||||
use RedirectDestinationTrait;
|
||||
|
||||
/**
|
||||
* The action storage.
|
||||
*
|
||||
|
@ -284,7 +287,7 @@ class BulkForm extends FieldPluginBase {
|
|||
$operation_definition = $action->getPluginDefinition();
|
||||
if (!empty($operation_definition['confirm_form_route_name'])) {
|
||||
$options = array(
|
||||
'query' => drupal_get_destination(),
|
||||
'query' => $this->getDestinationArray(),
|
||||
);
|
||||
$form_state->setRedirect($operation_definition['confirm_form_route_name'], array(), $options);
|
||||
}
|
||||
|
|
|
@ -729,7 +729,7 @@ function system_user_login(UserInterface $account) {
|
|||
$config = \Drupal::config('system.date');
|
||||
// If the user has a NULL time zone, notify them to set a time zone.
|
||||
if (!$account->getTimezone() && $config->get('timezone.user.configurable') && $config->get('timezone.user.warn')) {
|
||||
drupal_set_message(t('Configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => $account->url('edit-form', array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone')))));
|
||||
drupal_set_message(t('Configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => $account->url('edit-form', array('query' => \Drupal::destination()->getAsArray(), 'fragment' => 'edit-timezone')))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -89,9 +89,8 @@ class CommonTestController {
|
|||
* parameter.
|
||||
*/
|
||||
public function destination() {
|
||||
$destination = drupal_get_destination();
|
||||
$destination = \Drupal::destination()->getAsArray();
|
||||
$output = "The destination: " . SafeMarkup::checkPlain($destination['destination']);
|
||||
|
||||
return new Response($output);
|
||||
}
|
||||
|
||||
|
|
|
@ -200,7 +200,7 @@ class OverviewTerms extends FormBase {
|
|||
}
|
||||
|
||||
$errors = $form_state->getErrors();
|
||||
$destination = drupal_get_destination();
|
||||
$destination = $this->getDestinationArray();
|
||||
$row_position = 0;
|
||||
// Build the actual form.
|
||||
$form['terms'] = array(
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\taxonomy\Plugin\views\field;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\views\Plugin\views\field\FieldPluginBase;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
|
@ -23,6 +24,8 @@ use Drupal\views\ViewExecutable;
|
|||
*/
|
||||
class LinkEdit extends FieldPluginBase {
|
||||
|
||||
use RedirectDestinationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -78,7 +81,7 @@ class LinkEdit extends FieldPluginBase {
|
|||
));
|
||||
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_get_destination())));
|
||||
return \Drupal::l($text, new Url('entity.taxonomy.edit_form', ['taxonomy_term' => $tid], array('query' => $this->getDestinationArray())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -290,7 +290,7 @@ function update_storage_clear_submit($form, FormStateInterface $form_state) {
|
|||
* Returns a warning message when there is no data about available updates.
|
||||
*/
|
||||
function _update_no_data() {
|
||||
$destination = drupal_get_destination();
|
||||
$destination = \Drupal::destination()->getAsArray();
|
||||
return t('No update information available. <a href="@run_cron">Run cron</a> or <a href="@check_manually">check manually</a>.', array(
|
||||
'@run_cron' => \Drupal::url('system.run_cron', [], ['query' => $destination]),
|
||||
'@check_manually' => \Drupal::url('update.manual_status', [], ['query' => $destination]),
|
||||
|
@ -590,7 +590,7 @@ function _update_project_status_sort($a, $b) {
|
|||
*/
|
||||
function template_preprocess_update_last_check(&$variables) {
|
||||
$variables['time'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $variables['last']);
|
||||
$variables['link'] = \Drupal::l(t('Check manually'), new Url('update.manual_status', array(), array('query' => drupal_get_destination())));
|
||||
$variables['link'] = \Drupal::l(t('Check manually'), new Url('update.manual_status', array(), array('query' => \Drupal::destination()->getAsArray())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\user\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Routing\UrlGeneratorTrait;
|
||||
use Drupal\Core\Url;
|
||||
|
@ -27,6 +28,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
class UserLoginBlock extends BlockBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
use UrlGeneratorTrait;
|
||||
use RedirectDestinationTrait;
|
||||
|
||||
/**
|
||||
* The route match.
|
||||
|
@ -87,7 +89,7 @@ class UserLoginBlock extends BlockBase implements ContainerFactoryPluginInterfac
|
|||
unset($form['pass']['#description']);
|
||||
$form['name']['#size'] = 15;
|
||||
$form['pass']['#size'] = 15;
|
||||
$form['#action'] = $this->url('<current>', [], ['query' => drupal_get_destination(), 'external' => FALSE]);
|
||||
$form['#action'] = $this->url('<current>', [], ['query' => $this->getDestinationArray(), 'external' => FALSE]);
|
||||
// Build action links.
|
||||
$items = array();
|
||||
if (\Drupal::config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\user\Plugin\views\field;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\views\Plugin\views\field\FieldPluginBase;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
|
@ -24,6 +25,8 @@ use Drupal\Core\Entity\EntityInterface;
|
|||
*/
|
||||
class Link extends FieldPluginBase {
|
||||
|
||||
use RedirectDestinationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -29,7 +29,7 @@ class LinkCancel extends Link {
|
|||
$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_get_destination();
|
||||
$this->options['alter']['query'] = $this->getDestinationArray();
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class LinkEdit extends Link {
|
|||
|
||||
$text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Edit');
|
||||
|
||||
$this->options['alter']['url'] = $entity->urlInfo('edit-form', ['query' => ['destination' => drupal_get_destination()]]);
|
||||
$this->options['alter']['url'] = $entity->urlInfo('edit-form', ['query' => ['destination' => $this->getDestinationArray()]]);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityListBuilder;
|
|||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Routing\RedirectDestinationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
@ -36,6 +37,13 @@ class UserListBuilder extends EntityListBuilder {
|
|||
*/
|
||||
protected $dateFormatter;
|
||||
|
||||
/**
|
||||
* The redirect destination service.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\RedirectDestinationInterface
|
||||
*/
|
||||
protected $redirectDestination;
|
||||
|
||||
/**
|
||||
* Constructs a new UserListBuilder object.
|
||||
*
|
||||
|
@ -47,11 +55,14 @@ class UserListBuilder extends EntityListBuilder {
|
|||
* The entity query factory.
|
||||
* @param \Drupal\Core\Datetime\DateFormatter $date_formatter
|
||||
* The date formatter service.
|
||||
* @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
|
||||
* The redirect destination service.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, QueryFactory $query_factory, DateFormatter $date_formatter) {
|
||||
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, QueryFactory $query_factory, DateFormatter $date_formatter, RedirectDestinationInterface $redirect_destination) {
|
||||
parent::__construct($entity_type, $storage);
|
||||
$this->queryFactory = $query_factory;
|
||||
$this->dateFormatter = $date_formatter;
|
||||
$this->redirectDestination = $redirect_destination;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +73,8 @@ class UserListBuilder extends EntityListBuilder {
|
|||
$entity_type,
|
||||
$container->get('entity.manager')->getStorage($entity_type->id()),
|
||||
$container->get('entity.query'),
|
||||
$container->get('date.formatter')
|
||||
$container->get('date.formatter'),
|
||||
$container->get('redirect.destination')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -152,7 +164,7 @@ class UserListBuilder extends EntityListBuilder {
|
|||
public function getOperations(EntityInterface $entity) {
|
||||
$operations = parent::getOperations($entity);
|
||||
if (isset($operations['edit'])) {
|
||||
$destination = drupal_get_destination();
|
||||
$destination = $this->redirectDestination->getAsArray();
|
||||
$operations['edit']['query'] = $destination;
|
||||
}
|
||||
return $operations;
|
||||
|
|
|
@ -136,7 +136,7 @@ function hook_user_login($account) {
|
|||
$config = \Drupal::config('system.date');
|
||||
// If the user has a NULL time zone, notify them to set a time zone.
|
||||
if (!$account->getTimezone() && $config->get('timezone.user.configurable') && $config->get('timezone.user.warn')) {
|
||||
drupal_set_message(t('Configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => $account->url('edit-form', array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone')))));
|
||||
drupal_set_message(t('Configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => $account->url('edit-form', array('query' => \Drupal::destination()->getAsArray(), 'fragment' => 'edit-timezone')))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ class ViewAjaxController implements ContainerInjectionInterface {
|
|||
$request->query->replace($request_all + $query_all);
|
||||
|
||||
// Overwrite the destination.
|
||||
// @see drupal_get_destination()
|
||||
// @see the redirect.destination service.
|
||||
$origin_destination = $path;
|
||||
$query = UrlHelper::buildQuery($request->query->all());
|
||||
if ($query != '') {
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Drupal\views\Plugin\views\field;
|
|||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
use Drupal\views\ResultRow;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -21,6 +22,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
*/
|
||||
class EntityOperations extends FieldPluginBase {
|
||||
|
||||
use RedirectDestinationTrait;
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
*
|
||||
|
@ -102,7 +105,7 @@ class EntityOperations extends FieldPluginBase {
|
|||
if (!isset($operation['query'])) {
|
||||
$operation['query'] = array();
|
||||
}
|
||||
$operation['query'] += drupal_get_destination();
|
||||
$operation['query'] += $this->getDestinationArray();
|
||||
}
|
||||
}
|
||||
$build = array(
|
||||
|
|
|
@ -89,7 +89,7 @@ abstract class Links extends FieldPluginBase {
|
|||
'title' => $title,
|
||||
);
|
||||
if (!empty($this->options['destination'])) {
|
||||
$links[$field]['query'] = drupal_get_destination();
|
||||
$links[$field]['query'] = \Drupal::destination()->getAsArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -334,12 +334,3 @@ class ViewAjaxControllerTest extends UnitTestCase {
|
|||
|
||||
}
|
||||
|
||||
namespace {
|
||||
// @todo Remove once drupal_get_destination is converted to autoloadable code.
|
||||
if (!function_exists('drupal_static')) {
|
||||
function &drupal_static($key) {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,13 @@ class EntityOperationsUnitTest extends UnitTestCase {
|
|||
'title' => $this->randomMachineName(),
|
||||
);
|
||||
$this->plugin = new EntityOperations($configuration, $plugin_id, $plugin_definition, $this->entityManager);
|
||||
|
||||
$redirect_service = $this->getMock('Drupal\Core\Routing\RedirectDestinationInterface');
|
||||
$redirect_service->expects($this->any())
|
||||
->method('getAsArray')
|
||||
->willReturn(['destination' => 'foobar']);
|
||||
$this->plugin->setRedirectDestination($redirect_service);
|
||||
|
||||
$view = $this->getMockBuilder('\Drupal\views\ViewExecutable')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@ -108,7 +115,7 @@ class EntityOperationsUnitTest extends UnitTestCase {
|
|||
'#type' => 'operations',
|
||||
'#links' => $operations
|
||||
);
|
||||
$expected_build['#links']['foo']['query'] = drupal_get_destination();
|
||||
$expected_build['#links']['foo']['query'] = ['destination' => 'foobar'];
|
||||
$build = $this->plugin->render($result);
|
||||
$this->assertSame($expected_build, $build);
|
||||
}
|
||||
|
@ -156,15 +163,3 @@ class EntityOperationsUnitTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
if (!function_exists('drupal_get_destination')) {
|
||||
function drupal_get_destination() {
|
||||
return array(
|
||||
'destination' => 'foobar',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,6 +64,13 @@ class CustomPageExceptionHtmlSubscriberTest extends UnitTestCase {
|
|||
*/
|
||||
protected $customPageSubscriber;
|
||||
|
||||
/**
|
||||
* The mocked redirect.destination service.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\RedirectDestinationInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $redirectDestination;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -73,7 +80,13 @@ class CustomPageExceptionHtmlSubscriberTest extends UnitTestCase {
|
|||
$this->aliasManager = $this->getMock('Drupal\Core\Path\AliasManagerInterface');
|
||||
$this->kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
$this->logger = $this->getMock('Psr\Log\LoggerInterface');
|
||||
$this->customPageSubscriber = new TestCustomPageExceptionHtmlSubscriber($this->configFactory, $this->aliasManager, $this->kernel, $this->logger);
|
||||
$this->redirectDestination = $this->getMock('\Drupal\Core\Routing\RedirectDestinationInterface');
|
||||
|
||||
$this->redirectDestination->expects($this->any())
|
||||
->method('getAsArray')
|
||||
->willReturn(['destination' => 'test']);
|
||||
|
||||
$this->customPageSubscriber = new CustomPageExceptionHtmlSubscriber($this->configFactory, $this->aliasManager, $this->kernel, $this->logger, $this->redirectDestination);
|
||||
|
||||
// You can't create an exception in PHP without throwing it. Store the
|
||||
// current error_log, and disable it temporarily.
|
||||
|
@ -139,13 +152,3 @@ class CustomPageExceptionHtmlSubscriberTest extends UnitTestCase {
|
|||
|
||||
}
|
||||
|
||||
class TestCustomPageExceptionHtmlSubscriber extends CustomPageExceptionHtmlSubscriber {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function drupalGetDestination() {
|
||||
return ['destination' => 'test'];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue