diff --git a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php index 59dc1cc..6fed6f7 100644 --- a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php @@ -7,6 +7,7 @@ namespace Drupal\Core\EventSubscriber; +use Drupal\Core\Routing\RedirectDestinationInterface; use Drupal\Core\Url; use Drupal\Core\Utility\Error; use Psr\Log\LoggerInterface; @@ -35,16 +36,26 @@ class DefaultExceptionHtmlSubscriber extends HttpExceptionSubscriberBase { protected $logger; /** + * The redirect destination service. + * + * @var \Drupal\Core\Routing\RedirectDestinationInterface + */ + protected $redirectDestination; + + /** * Constructs a new DefaultExceptionHtmlSubscriber. * * @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel * 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; } /** @@ -104,10 +115,10 @@ protected function makeSubrequest(GetResponseForExceptionEvent $event, $url, $st 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->getAsArrays() + ['_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 { @@ -133,11 +144,4 @@ protected function makeSubrequest(GetResponseForExceptionEvent $event, $url, $st } } - /** - * Wraps drupal_get_destination(). - */ - protected function drupalGetDestination() { - return \Drupal::service('redirect.destination')->getAsArray(); - } - } diff --git a/core/modules/book/src/Form/BookAdminEditForm.php b/core/modules/book/src/Form/BookAdminEditForm.php index 1fb7723..0939476 100644 --- a/core/modules/book/src/Form/BookAdminEditForm.php +++ b/core/modules/book/src/Form/BookAdminEditForm.php @@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\RedirectDestinationInterface; use Drupal\Core\Render\Element; use Drupal\Core\Url; use Drupal\node\NodeInterface; @@ -38,16 +39,26 @@ class BookAdminEditForm extends FormBase { protected $bookManager; /** + * The redirect destination service. + * + * @var \Drupal\Core\Routing\RedirectDestinationInterface + */ + protected $redirectDestination; + + /** * Constructs a new BookAdminEditForm. * * @param \Drupal\Core\Entity\EntityStorageInterface $node_storage * The custom block storage. * @param \Drupal\book\BookManagerInterface $book_manager * The book manager. + * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination + * The redirect destination service. */ - public function __construct(EntityStorageInterface $node_storage, BookManagerInterface $book_manager) { + public function __construct(EntityStorageInterface $node_storage, BookManagerInterface $book_manager, RedirectDestinationInterface $redirect_destination) { $this->nodeStorage = $node_storage; $this->bookManager = $book_manager; + $this->redirectDestination = $redirect_destination; } /** @@ -206,7 +217,7 @@ protected function bookAdminTableTree(array $tree, array &$form) { $delta = ($count < 30) ? 15 : intval($count / 2) + 1; $access = \Drupal::currentUser()->hasPermission('administer nodes'); - $destination = \Drupal::service('redirect.destination')->getAsArray(); + $destination = $this->redirectDestination->getAsArray(); foreach ($tree as $data) { $nid = $data['link']['nid']; diff --git a/core/modules/comment/src/Form/CommentAdminOverview.php b/core/modules/comment/src/Form/CommentAdminOverview.php index 68c172d..cef1748 100644 --- a/core/modules/comment/src/Form/CommentAdminOverview.php +++ b/core/modules/comment/src/Form/CommentAdminOverview.php @@ -15,6 +15,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\RedirectDestinationInterface; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -52,6 +53,13 @@ class CommentAdminOverview extends FormBase { protected $moduleHandler; /** + * The redirect destination service. + * + * @var \Drupal\Core\Routing\RedirectDestinationInterface + */ + protected $redirectDestination; + + /** * Creates a CommentAdminOverview form. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -62,12 +70,15 @@ class CommentAdminOverview extends FormBase { * The date formatter service. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. + * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination + * The redirect destination service. */ - public function __construct(EntityManagerInterface $entity_manager, CommentStorageInterface $comment_storage, DateFormatter $date_formatter, ModuleHandlerInterface $module_handler) { + public function __construct(EntityManagerInterface $entity_manager, CommentStorageInterface $comment_storage, DateFormatter $date_formatter, ModuleHandlerInterface $module_handler, RedirectDestinationInterface $redirect_destination) { $this->entityManager = $entity_manager; $this->commentStorage = $comment_storage; $this->dateFormatter = $date_formatter; $this->moduleHandler = $module_handler; + $this->redirectDestination = $redirect_destination; } /** @@ -167,7 +178,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $type = ' // Build a table listing the appropriate comments. $options = array(); - $destination = \Drupal::service('redirect.destination')->getAsArray(); + $destination = $this->redirectDestination->getAsArray(); $commented_entity_ids = array(); $commented_entities = array(); diff --git a/core/modules/field_ui/src/Form/FieldEditForm.php b/core/modules/field_ui/src/Form/FieldEditForm.php index 668809d..c860191 100644 --- a/core/modules/field_ui/src/Form/FieldEditForm.php +++ b/core/modules/field_ui/src/Form/FieldEditForm.php @@ -12,6 +12,7 @@ use Drupal\Core\Form\FormBase; use Drupal\Component\Utility\String; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\RedirectDestinationInterface; use Drupal\field\FieldConfigInterface; use Drupal\field_ui\FieldUI; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -38,13 +39,23 @@ class FieldEditForm extends FormBase { protected $entityManager; /** + * The redirect destination service. + * + * @var \Drupal\Core\Routing\RedirectDestinationInterface + */ + protected $redirectDestination; + + /** * Constructs a new field form. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. + * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination + * The redirect destination service. */ - public function __construct(EntityManagerInterface $entity_manager) { + public function __construct(EntityManagerInterface $entity_manager, RedirectDestinationInterface $redirect_destination) { $this->entityManager = $entity_manager; + $this->redirectDestination = $redirect_destination; } /** @@ -219,7 +230,7 @@ public function delete(array &$form, FormStateInterface $form_state) { $destination = array(); $request = $this->getRequest(); if ($request->query->has('destination')) { - $destination = \Drupal::service('redirect.destination')->getAsArray(); + $destination = $this->redirectDestination->getAsArray(); $request->query->remove('destination'); } $entity_type = $this->entityManager->getDefinition($this->field->entity_type); diff --git a/core/modules/field_ui/src/Form/FieldStorageAddForm.php b/core/modules/field_ui/src/Form/FieldStorageAddForm.php index 1ad08e5..10b88a3 100644 --- a/core/modules/field_ui/src/Form/FieldStorageAddForm.php +++ b/core/modules/field_ui/src/Form/FieldStorageAddForm.php @@ -13,6 +13,7 @@ use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\RedirectDestinationInterface; use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\FieldStorageConfigInterface; use Drupal\field_ui\FieldUI; @@ -66,6 +67,13 @@ class FieldStorageAddForm extends FormBase { protected $configFactory; /** + * The redirect destination service. + * + * @var \Drupal\Core\Routing\RedirectDestinationInterface + */ + protected $redirectDestination; + + /** * Constructs a new FieldStorageAddForm object. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -76,12 +84,15 @@ class FieldStorageAddForm extends FormBase { * The configuration factory. * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory * The entity query factory. + * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination + * The redirect destination service. */ - public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, QueryFactory $query_factory, ConfigFactoryInterface $config_factory) { + public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, QueryFactory $query_factory, ConfigFactoryInterface $config_factory, RedirectDestinationInterface $redirect_destination) { $this->entityManager = $entity_manager; $this->fieldTypePluginManager = $field_type_plugin_manager; $this->queryFactory = $query_factory; $this->configFactory = $config_factory; + $this->redirectDestination = $redirect_destination; } /** @@ -382,7 +393,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } if ($destinations) { - $destination = \Drupal::service('redirect.destination')->getAsArray(); + $destination = $this->redirectDestination->getAsArray(); $destinations[] = $destination['destination']; $form_state->setRedirectUrl(FieldUI::getNextDestination($destinations, $form_state)); }