Verified Commit 9ed7086e authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3123214 by nitesh624, jungle, mrinalini9, Suresh Prabhu Parkala,...

Issue #3123214 by nitesh624, jungle, mrinalini9, Suresh Prabhu Parkala, ranjith_kumar_k_u, smustgrave: Inject redirect.destination service instead of using \Drupal:: destination() in non-tests
parent 6a9c88c8
Loading
Loading
Loading
Loading
+35 −1
Original line number Diff line number Diff line
@@ -4,7 +4,9 @@

use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RedirectDestinationInterface;
use Drupal\Core\Url as UrlObject;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * An abstract handler which provides a collection of links.
@@ -13,6 +15,38 @@
 */
abstract class Links extends FieldPluginBase {

  /**
   * Constructs a Links object.
   *
   * @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|null $redirectDestination
   *   The redirect destination service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, protected ?RedirectDestinationInterface $redirectDestination = NULL) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    if ($redirectDestination === NULL) {
      $this->redirectDestination = \Drupal::service('redirect.destination');
      @trigger_error('Calling' . __METHOD__ . '() without the $redirectDestination argument is deprecated in drupal:10.1.0 and is required in drupal:11.0.0. See https://www.drupal.org/node/3343983', E_USER_DEPRECATED);
    }
  }

  /**
   * {@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}
   */
@@ -84,7 +118,7 @@ protected function getLinks() {
        'title' => $title,
      ];
      if (!empty($this->options['destination'])) {
        $links[$field]['query'] = \Drupal::destination()->getAsArray();
        $links[$field]['query'] = $this->redirectDestination->getAsArray();
      }
    }

+11 −3
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RedirectDestinationInterface;
use Drupal\Core\Url;
use Drupal\workspaces\WorkspaceInterface;
use Drupal\workspaces\WorkspaceOperationFactory;
@@ -51,10 +52,16 @@ class WorkspaceMergeForm extends ConfirmFormBase implements WorkspaceFormInterfa
   *   The workspace operation factory service.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Routing\RedirectDestinationInterface|null $redirectDestination
   *   The redirect destination service.
   */
  public function __construct(WorkspaceOperationFactory $workspace_operation_factory, EntityTypeManagerInterface $entity_type_manager) {
  public function __construct(WorkspaceOperationFactory $workspace_operation_factory, EntityTypeManagerInterface $entity_type_manager, ?RedirectDestinationInterface $redirectDestination = NULL) {
    $this->workspaceOperationFactory = $workspace_operation_factory;
    $this->entityTypeManager = $entity_type_manager;
    if ($redirectDestination === NULL) {
      $this->redirectDestination = \Drupal::service('redirect.destination');
      @trigger_error('Calling' . __METHOD__ . '() without the $redirectDestination argument is deprecated in drupal:10.1.0 and is required in drupal:11.0.0. See https://www.drupal.org/node/3343983', E_USER_DEPRECATED);
    }
  }

  /**
@@ -63,7 +70,8 @@ public function __construct(WorkspaceOperationFactory $workspace_operation_facto
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('workspaces.operation_factory'),
      $container->get('entity_type.manager')
      $container->get('entity_type.manager'),
      $container->get('redirect.destination')
    );
  }

@@ -136,7 +144,7 @@ public function getDescription() {
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return Url::fromRoute('entity.workspace.collection', [], ['query' => \Drupal::destination()->getAsArray()]);
    return Url::fromRoute('entity.workspace.collection', [], ['query' => $this->redirectDestination->getAsArray()]);
  }

  /**
+11 −3
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RedirectDestinationInterface;
use Drupal\Core\Url;
use Drupal\workspaces\WorkspaceAccessException;
use Drupal\workspaces\WorkspaceInterface;
@@ -45,10 +46,16 @@ class WorkspacePublishForm extends ConfirmFormBase implements WorkspaceFormInter
   *   The workspace operation factory service.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Routing\RedirectDestinationInterface|null $redirectDestination
   *   The redirect destination service.
   */
  public function __construct(WorkspaceOperationFactory $workspace_operation_factory, EntityTypeManagerInterface $entity_type_manager) {
  public function __construct(WorkspaceOperationFactory $workspace_operation_factory, EntityTypeManagerInterface $entity_type_manager, ?RedirectDestinationInterface $redirectDestination = NULL) {
    $this->workspaceOperationFactory = $workspace_operation_factory;
    $this->entityTypeManager = $entity_type_manager;
    if ($redirectDestination === NULL) {
      $this->redirectDestination = \Drupal::service('redirect.destination');
      @trigger_error('Calling' . __METHOD__ . '() without the $redirectDestination argument is deprecated in drupal:10.1.0 and is required in drupal:11.0.0. See https://www.drupal.org/node/3343983', E_USER_DEPRECATED);
    }
  }

  /**
@@ -57,7 +64,8 @@ public function __construct(WorkspaceOperationFactory $workspace_operation_facto
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('workspaces.operation_factory'),
      $container->get('entity_type.manager')
      $container->get('entity_type.manager'),
      $container->get('redirect.destination')
    );
  }

@@ -133,7 +141,7 @@ public function getDescription() {
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return Url::fromRoute('entity.workspace.collection', [], ['query' => \Drupal::destination()->getAsArray()]);
    return Url::fromRoute('entity.workspace.collection', [], ['query' => $this->redirectDestination->getAsArray()]);
  }

  /**