UrlGeneratorInterface.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Drupal\Core\Routing;
  3. use Symfony\Cmf\Component\Routing\VersatileGeneratorInterface;
  4. /**
  5. * Defines an interface for generating a url from a route or system path.
  6. *
  7. * Provides additional methods and options not present in the base interface.
  8. */
  9. interface UrlGeneratorInterface extends VersatileGeneratorInterface {
  10. /**
  11. * Gets the internal path (system path) for a route.
  12. *
  13. * @param string|\Symfony\Component\Routing\Route $name
  14. * The route name or a route object.
  15. * @param array $parameters
  16. * An array of parameters as passed to
  17. * \Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate().
  18. *
  19. * @return string
  20. * The internal Drupal path corresponding to the route. This string is
  21. * not urlencoded and will be an empty string for the front page.
  22. */
  23. public function getPathFromRoute($name, $parameters = []);
  24. /**
  25. * Generates a URL or path for a specific route based on the given parameters.
  26. *
  27. * Parameters that reference placeholders in the route pattern will be
  28. * substituted for them in the pattern. Extra params are added as query
  29. * strings to the URL.
  30. *
  31. * @param string|\Symfony\Component\Routing\Route $name
  32. * The route name or a route object.
  33. * @param array $parameters
  34. * An associative array of parameter names and values.
  35. * @param array $options
  36. * (optional) An associative array of additional options, with the following
  37. * elements:
  38. * - 'query': An array of query key/value-pairs (without any URL-encoding)
  39. * to append to the URL.
  40. * - 'fragment': A fragment identifier (named anchor) to append to the URL.
  41. * Do not include the leading '#' character.
  42. * - 'absolute': Defaults to FALSE. Whether to force the output to be an
  43. * absolute link (beginning with http:). Useful for links that will be
  44. * displayed outside the site, such as in an RSS feed.
  45. * - 'language': An optional language object used to look up the alias
  46. * for the URL. If $options['language'] is omitted, it defaults to the
  47. * current language for the language type LanguageInterface::TYPE_URL.
  48. * - 'https': Whether this URL should point to a secure location. If not
  49. * defined, the current scheme is used, so the user stays on HTTP or HTTPS
  50. * respectively. TRUE enforces HTTPS and FALSE enforces HTTP.
  51. * - 'base_url': Only used internally by a path processor, for example, to
  52. * modify the base URL when a language dependent URL requires so.
  53. * - 'prefix': Only used internally, to modify the path when a language
  54. * dependent URL requires so.
  55. * @param bool $collect_bubbleable_metadata
  56. * (optional) Defaults to FALSE. When TRUE, both the generated URL and its
  57. * associated bubbleable metadata are returned.
  58. *
  59. * @return string|\Drupal\Core\GeneratedUrl
  60. * The generated URL for the given route.
  61. * When $collect_bubbleable_metadata is TRUE, a GeneratedUrl object is
  62. * returned, containing the generated URL plus bubbleable metadata.
  63. *
  64. * @throws \Symfony\Component\Routing\Exception\RouteNotFoundException
  65. * Thrown when the named route does not exist.
  66. * @throws \Symfony\Component\Routing\Exception\MissingMandatoryParametersException
  67. * Thrown when some parameters are missing that are mandatory for the route.
  68. * @throws \Symfony\Component\Routing\Exception\InvalidParameterException
  69. * Thrown when a parameter value for a placeholder is not correct because it
  70. * does not match the requirement.
  71. *
  72. * @internal
  73. * Should not be used in user code.
  74. * Use \Drupal\Core\Url instead.
  75. */
  76. public function generateFromRoute($name, $parameters = [], $options = [], $collect_bubbleable_metadata = FALSE);
  77. }