RedirectDestinationInterface.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Drupal\Core\Routing;
  3. /**
  4. * Provides an interface for redirect destinations.
  5. */
  6. interface RedirectDestinationInterface {
  7. /**
  8. * Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
  9. *
  10. * Used to direct the user back to the referring page after completing a form.
  11. * By default the current URL is returned. If a destination exists in the
  12. * current request, that destination is returned. As such, a destination can
  13. * persist across multiple pages.
  14. *
  15. * @return array
  16. * An associative array containing the key:
  17. * - destination: The value of the current request's 'destination' query
  18. * parameter, if present. This can be either a relative or absolute URL.
  19. * However, for security, redirection to external URLs is not performed.
  20. * If the query parameter isn't present, then the URL of the current
  21. * request is returned.
  22. *
  23. * @see \Drupal\Core\EventSubscriber\RedirectResponseSubscriber::checkRedirectUrl()
  24. * @ingroup form_api
  25. */
  26. public function getAsArray();
  27. /**
  28. * Gets the destination as a path.
  29. *
  30. * To convert to a URL suitable for
  31. * \Symfony\Component\HttpFoundation\RedirectResponse::__construct() use
  32. * @code
  33. * \Drupal\Core\Url::fromUserInput(\Drupal::destination()->get())->setAbsolute()->toString()
  34. * @endcode
  35. *
  36. * @return string
  37. */
  38. public function get();
  39. /**
  40. * Sets the destination as URL.
  41. *
  42. * This method should be used really rarely, for example views uses it, in
  43. * order to override all destination calls in all of its rendering.
  44. *
  45. * @param string $new_destination
  46. * The new destination.
  47. *
  48. * @return $this
  49. */
  50. public function set($new_destination);
  51. }