1. 8.5.x core/lib/Drupal/Core/Routing/RedirectDestinationTrait.php RedirectDestinationTrait
  2. 8.0.x core/lib/Drupal/Core/Routing/RedirectDestinationTrait.php RedirectDestinationTrait
  3. 8.1.x core/lib/Drupal/Core/Routing/RedirectDestinationTrait.php RedirectDestinationTrait
  4. 8.2.x core/lib/Drupal/Core/Routing/RedirectDestinationTrait.php RedirectDestinationTrait
  5. 8.3.x core/lib/Drupal/Core/Routing/RedirectDestinationTrait.php RedirectDestinationTrait
  6. 8.4.x core/lib/Drupal/Core/Routing/RedirectDestinationTrait.php RedirectDestinationTrait
  7. 8.6.x core/lib/Drupal/Core/Routing/RedirectDestinationTrait.php RedirectDestinationTrait

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.

Hierarchy

9 files declare their use of RedirectDestinationTrait
BlockContentListBuilder.php in core/modules/block_content/src/BlockContentListBuilder.php
BulkForm.php in core/modules/system/src/Plugin/views/field/BulkForm.php
ContextualLinks.php in core/modules/contextual/src/Plugin/views/field/ContextualLinks.php
ControllerBase.php in core/lib/Drupal/Core/Controller/ControllerBase.php
EntityOperations.php in core/modules/views/src/Plugin/views/field/EntityOperations.php

... See full list

File

core/lib/Drupal/Core/Routing/RedirectDestinationTrait.php, line 13

Namespace

Drupal\Core\Routing
View source
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;
  }

}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description Overrides
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service.
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.