diff --git a/core/includes/common.inc b/core/includes/common.inc index c6f6688dff4719ebf880ecf7653f14e8ad0b1179..eb7362cb473c603e8878fb13142d6df9a0238714 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -448,6 +448,7 @@ function drupal_get_query_parameters(array $query = NULL, array $exclude = array /** * Parses an array into a valid, rawurlencoded query string. * + * @see \Drupal\Core\Routing\PathBasedGeneratorInterface::httpBuildQuery() * @see drupal_get_query_parameters() * @deprecated as of Drupal 8.0. Use Url::buildQuery() instead. * @ingroup php_wrappers @@ -1191,7 +1192,7 @@ function datetime_default_format_type() { * When creating links in modules, consider whether l() could be a better * alternative than url(). * - * @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromPath(). + * @see \Drupal\Core\Routing\PathBasedGeneratorInterface::generateFromPath(). */ function url($path = NULL, array $options = array()) { $generator = Drupal::urlGenerator(); diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index aac234963fa8452f098b42d715e26c9c489c9f26..d0e33e319fc7442fa677fd20bbf537e254ed4685 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -364,7 +364,7 @@ public static function token() { /** * Returns the url generator service. * - * @return \Drupal\Core\Routing\UrlGeneratorInterface + * @return \Drupal\Core\Routing\PathBasedGeneratorInterface * The url generator service. */ public static function urlGenerator() { diff --git a/core/lib/Drupal/Core/Controller/ControllerBase.php b/core/lib/Drupal/Core/Controller/ControllerBase.php index 15d6cc81acdfa99f3eb9df2a98558efaf7ef1f7b..d9cc1914eaa9b4de7ec39bd14e2549ffa0c06c69 100644 --- a/core/lib/Drupal/Core/Controller/ControllerBase.php +++ b/core/lib/Drupal/Core/Controller/ControllerBase.php @@ -114,7 +114,7 @@ protected function moduleHandler() { /** * Returns the url generator service. * - * @return \Drupal\Core\Routing\UrlGeneratorInterface + * @return \Drupal\Core\Routing\PathBasedGeneratorInterface * The url generator service. */ protected function urlGenerator() { diff --git a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php index 6aaf27a841862ecd977f45cc92a28af625d6b899..fb60160272751aea45b3b064d9f77e569e15b80e 100644 --- a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php @@ -9,6 +9,7 @@ use Drupal\Core\CacheDecorator\AliasManagerCacheDecorator; use Drupal\Core\PathProcessor\InboundPathProcessorInterface; +use Drupal\Core\Routing\PathBasedGeneratorInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; diff --git a/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php index 376dee372fb336e19e85aefd060add1427c102bb..9da318eb867195cd97436190da6af95fd4eb2247 100644 --- a/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php @@ -7,7 +7,7 @@ namespace Drupal\Core\EventSubscriber; -use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Routing\PathBasedGeneratorInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; @@ -22,17 +22,17 @@ class RedirectResponseSubscriber implements EventSubscriberInterface { /** * The url generator service. * - * @var \Drupal\Core\Routing\UrlGeneratorInterface + * @var \Drupal\Core\Routing\PathBasedGeneratorInterface */ protected $urlGenerator; /** * Constructs a RedirectResponseSubscriber object. * - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator + * @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator * The url generator service. */ - public function __construct(UrlGeneratorInterface $url_generator) { + public function __construct(PathBasedGeneratorInterface $url_generator) { $this->urlGenerator = $url_generator; } diff --git a/core/lib/Drupal/Core/Routing/NullGenerator.php b/core/lib/Drupal/Core/Routing/NullGenerator.php index b6e26097fde15a11c7ab8e8c7d5648540effef02..8970247b9771bcb1a3a9cc6e640e988a8fdabff5 100644 --- a/core/lib/Drupal/Core/Routing/NullGenerator.php +++ b/core/lib/Drupal/Core/Routing/NullGenerator.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Routing; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\Exception\RouteNotFoundException; @@ -22,12 +23,9 @@ public function __construct() { } /** - * {@inheritdoc} - * - * generate(), generateFromRoute(), and getPathFromRoute() all call this - * protected method. + * Overrides Drupal\Core\Routing\UrlGenerator::generate(); */ - protected function getRoute($name) { + public function generate($name, $parameters = array(), $absolute = FALSE) { throw new RouteNotFoundException(); } diff --git a/core/lib/Drupal/Core/Routing/PathBasedGeneratorInterface.php b/core/lib/Drupal/Core/Routing/PathBasedGeneratorInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..79ed3738d9251a6acde9ad93d3ca67cefa38ebe3 --- /dev/null +++ b/core/lib/Drupal/Core/Routing/PathBasedGeneratorInterface.php @@ -0,0 +1,107 @@ +<?php + +/** + * @file + * Contains Drupal\Core\Routing\PathBasedGeneratorInterface. + */ + +namespace Drupal\Core\Routing; + +use Symfony\Component\HttpFoundation\Request; + +/** + * Defines an interface for generating a url from a path as opposed to a route. + */ +interface PathBasedGeneratorInterface { + + /** + * Generates an internal or external URL. + * + * @param $path + * (optional) The internal path or external URL being linked to, such as + * "node/34" or "http://example.com/foo". + * + * @param $options + * (optional) An associative array of additional options. + * + * @return + * A string containing a URL to the given path. + */ + public function generateFromPath($path = NULL, $options = array()); + + /** + * Gets the internal path of a route. + * + * @param string $name + * The route name. + * @param array $parameters + * An array of parameters as passed to + * \Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate(). + * + * @return string + * The internal Drupal path corresponding to the route. + */ + public function getPathFromRoute($name, $parameters = array()); + + /** + * Sets the $request property. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * The HttpRequest object representing the current request. + */ + public function setRequest(Request $request); + + /** + * Sets the baseUrl property. + * + * This property is made up of scheme, host and base_path, e.g. + * 'http://www.example.com/mydrupalinstall/' + * + * The base url is usually set by the request but we allow it to be set + * independent of the request so that code that calls url() outside the context + * of a request can use the global $base_url variable to set this value. + * + * @todo Remove this once the url() function no longer supports being called + * when there is no request. + * + * @var string $url + * The base url to use for url generation. + */ + public function setBaseUrl($url); + + /** + * Sets the basePath property. + * + * This will be either '/' or '[subdir]/', where [subdir] is the name of the + * subdirectory that Drupal is running in. + * + * The base path is usually set by the request but we allow it to be set + * independent of the request so that code that calls url() outside the context + * of a request can use the global $base_url variable to set this value. + * + * @todo Remove this once the url() function no longer supports being called + * when there is no request. + * + * @var string $path + * The base path to use for url generation. + */ + public function setBasePath($path); + + /** + * Sets the scriptPath property. + * + * The script path is usually set by the request and is either 'index.php' or + * the empty string, depending on whether the request path actually contains + * the script path or not. We allow it to be set independent of the request so + * that code that calls url() outside the context of a request can use the global + * $script_path variable to set this value. + * + * @todo Remove this once the url() function no longer supports being called + * when there is no request. + * + * @var string $path + * The script path to use for url generation. + */ + public function setScriptPath($path); + +} diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php index ac5d5c8beccf11ecf5c3b8601565149e1cf44bb6..402caa63cec8035aa81a9f476c62016160a7c2cc 100644 --- a/core/lib/Drupal/Core/Routing/UrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php @@ -23,7 +23,7 @@ /** * A Generator creates URL strings based on a specified route. */ -class UrlGenerator extends ProviderBasedGenerator implements UrlGeneratorInterface { +class UrlGenerator extends ProviderBasedGenerator implements PathBasedGeneratorInterface { /** * A request object. @@ -87,7 +87,7 @@ public function __construct(RouteProviderInterface $provider, OutboundPathProces } /** - * {@inheritdoc} + * Implements \Drupal\Core\Routing\PathBasedGeneratorInterface::setRequest(). */ public function setRequest(Request $request) { $this->request = $request; @@ -108,7 +108,7 @@ public function setRequest(Request $request) { * {@inheritdoc} */ public function getPathFromRoute($name, $parameters = array()) { - $route = $this->getRoute($name); + $route = $this->getRoute($name, $parameters); $path = $this->getInternalPathFromRoute($route, $parameters); // Router-based paths may have a querystring on them but Drupal paths may // not have one, so remove any ? and anything after it. For generate() this @@ -157,41 +157,18 @@ protected function getInternalPathFromRoute(SymfonyRoute $route, $parameters = a * {@inheritdoc} */ public function generate($name, $parameters = array(), $absolute = FALSE) { - $options['absolute'] = $absolute; - return $this->generateFromRoute($name, $parameters, $options); - } - - /** - * {@inheritdoc} - */ - public function generateFromRoute($name, $parameters = array(), $options = array()) { - $absolute = !empty($options['absolute']); - $route = $this->getRoute($name); - // Symfony adds any parameters that are not path slugs as query strings. - if (isset($options['query']) && is_array($options['query'])) { - $parameters = (array) $parameters + $options['query']; - } + $route = $this->getRoute($name, $parameters); $path = $this->getInternalPathFromRoute($route, $parameters); - $path = $this->processPath($path, $options); - $fragment = ''; - if (isset($options['fragment'])) { - if (($fragment = trim($options['fragment'])) != '') { - $fragment = '#' . $fragment; - } - } + $path = $this->processPath($path); + $base_url = $this->context->getBaseUrl(); if (!$absolute || !$host = $this->context->getHost()) { - return $base_url . $path . $fragment; + return $base_url . $path; } // Prepare an absolute URL by getting the correct scheme, host and port from // the request context. - if (isset($options['https']) && $this->mixedModeSessions) { - $scheme = $options['https'] ? 'https' : 'http'; - } - else { - $scheme = $this->context->getScheme(); - } + $scheme = $this->context->getScheme(); $scheme_req = $route->getRequirement('_scheme'); if (isset($scheme_req) && ($req = strtolower($scheme_req)) && $scheme !== $req) { $scheme = $req; @@ -202,11 +179,68 @@ public function generateFromRoute($name, $parameters = array(), $options = array } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) { $port = ':' . $this->context->getHttpsPort(); } - return $scheme . '://' . $host . $port . $base_url . $path . $fragment; + return $scheme . '://' . $host . $port . $base_url . $path; } /** - * {@inheritdoc} + * Implements \Drupal\Core\Routing\PathBasedGeneratorInterface::generateFromPath(). + * + * @param $path + * (optional) The internal path or external URL being linked to, such as + * "node/34" or "http://example.com/foo". The default value is equivalent to + * passing in '<front>'. A few notes: + * - If you provide a full URL, it will be considered an external URL. + * - If you provide only the path (e.g. "node/34"), it will be + * considered an internal link. In this case, it should be a system URL, + * and it will be replaced with the alias, if one exists. Additional query + * arguments for internal paths must be supplied in $options['query'], not + * included in $path. + * - If you provide an internal path and $options['alias'] is set to TRUE, the + * path is assumed already to be the correct path alias, and the alias is + * not looked up. + * - The special string '<front>' generates a link to the site's base URL. + * - If your external URL contains a query (e.g. http://example.com/foo?a=b), + * then you can either URL encode the query keys and values yourself and + * include them in $path, or use $options['query'] to let this method + * URL encode them. + * + * @param $options + * (optional) An associative array of additional options, with the following + * elements: + * - 'query': An array of query key/value-pairs (without any URL-encoding) to + * append to the URL. + * - 'fragment': A fragment identifier (named anchor) to append to the URL. + * Do not include the leading '#' character. + * - 'absolute': Defaults to FALSE. Whether to force the output to be an + * absolute link (beginning with http:). Useful for links that will be + * displayed outside the site, such as in an RSS feed. + * - 'alias': Defaults to FALSE. Whether the given path is a URL alias + * already. + * - 'external': Whether the given path is an external URL. + * - 'language': An optional language object. If the path being linked to is + * internal to the site, $options['language'] is used to look up the alias + * for the URL. If $options['language'] is omitted, the language will be + * obtained from language(Language::TYPE_URL). + * - 'https': Whether this URL should point to a secure location. If not + * defined, the current scheme is used, so the user stays on HTTP or HTTPS + * respectively. TRUE enforces HTTPS and FALSE enforces HTTP, but HTTPS can + * only be enforced when the variable 'https' is set to TRUE. + * - 'base_url': Only used internally, to modify the base URL when a language + * dependent URL requires so. + * - 'prefix': Only used internally, to modify the path when a language + * dependent URL requires so. + * - 'script': Added to the URL between the base path and the path prefix. + * Defaults to empty string when clean URLs are in effect, and to + * 'index.php/' when they are not. + * - 'entity_type': The entity type of the object that called url(). Only + * set if url() is invoked by Drupal\Core\Entity\Entity::uri(). + * - 'entity': The entity object (such as a node) for which the URL is being + * generated. Only set if url() is invoked by Drupal\Core\Entity\Entity::uri(). + * + * @return + * A string containing a URL to the given path. + * + * @throws \Drupal\Core\Routing\GeneratorNotInitializedException. */ public function generateFromPath($path = NULL, $options = array()) { @@ -295,21 +329,21 @@ public function generateFromPath($path = NULL, $options = array()) { } /** - * {@inheritdoc} + * Implements \Drupal\Core\Routing\PathBasedGeneratorInterface::setBaseUrl(). */ public function setBaseUrl($url) { $this->baseUrl = $url; } /** - * {@inheritdoc} + * Implements \Drupal\Core\Routing\PathBasedGeneratorInterface::setBasePath(). */ public function setBasePath($path) { $this->basePath = $path; } /** - * {@inheritdoc} + * Implements \Drupal\Core\Routing\PathBasedGeneratorInterface::setScriptPath(). */ public function setScriptPath($path) { $this->scriptPath = $path; @@ -347,10 +381,13 @@ protected function initialized() { } /** - * Find the route using the provided route name. + * Find the route using the provided route name (and parameters). * * @param string $name * The route name to fetch + * @param array $parameters + * The parameters as they are passed to the UrlGeneratorInterface::generate + * call. * * @return \Symfony\Component\Routing\Route * The found route. @@ -360,11 +397,11 @@ protected function initialized() { * * @see \Drupal\Core\Routing\RouteProviderInterface */ - protected function getRoute($name) { + protected function getRoute($name, $parameters) { if ($name instanceof SymfonyRoute) { $route = $name; } - elseif (NULL === $route = $this->provider->getRouteByName($name)) { + elseif (NULL === $route = $this->provider->getRouteByName($name, $parameters)) { throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name)); } return $route; diff --git a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php deleted file mode 100644 index 62fe1efe006e51fe8a21e6372db0794e55c2744e..0000000000000000000000000000000000000000 --- a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php +++ /dev/null @@ -1,202 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\Core\Routing\UrlGeneratorInterface. - */ - -namespace Drupal\Core\Routing; - -use Symfony\Component\HttpFoundation\Request; -use Symfony\Cmf\Component\Routing\VersatileGeneratorInterface; - -/** - * Defines an interface for generating a url from a route or system path. - * - * Provides additional methods and options not present in the base interface. - */ -interface UrlGeneratorInterface extends VersatileGeneratorInterface { - - /** - * Generates an internal or external URL. - * - * @param string $path - * (optional) The internal path or external URL being linked to, such as - * "node/34" or "http://example.com/foo". The default value is equivalent to - * passing in '<front>'. A few notes: - * - If you provide a full URL, it will be considered an external URL. - * - If you provide only the path (e.g. "node/34"), it will be - * considered an internal link. In this case, it should be a system URL, - * and it will be replaced with the alias, if one exists. Additional query - * arguments for internal paths must be supplied in $options['query'], not - * included in $path. - * - If you provide an internal path and $options['alias'] is set to TRUE, the - * path is assumed already to be the correct path alias, and the alias is - * not looked up. - * - The special string '<front>' generates a link to the site's base URL. - * - If your external URL contains a query (e.g. http://example.com/foo?a=b), - * then you can either URL encode the query keys and values yourself and - * include them in $path, or use $options['query'] to let this method - * URL encode them. - * - * @param array $options - * (optional) An associative array of additional options, with the following - * elements: - * - 'query': An array of query key/value-pairs (without any URL-encoding) to - * append to the URL. - * - 'fragment': A fragment identifier (named anchor) to append to the URL. - * Do not include the leading '#' character. - * - 'absolute': Defaults to FALSE. Whether to force the output to be an - * absolute link (beginning with http:). Useful for links that will be - * displayed outside the site, such as in an RSS feed. - * - 'alias': Defaults to FALSE. Whether the given path is a URL alias - * already. - * - 'external': Whether the given path is an external URL. - * - 'language': An optional language object. If the path being linked to is - * internal to the site, $options['language'] is used to look up the alias - * for the URL. If $options['language'] is omitted, the language will be - * obtained from language(Language::TYPE_URL). - * - 'https': Whether this URL should point to a secure location. If not - * defined, the current scheme is used, so the user stays on HTTP or HTTPS - * respectively. TRUE enforces HTTPS and FALSE enforces HTTP, but HTTPS can - * only be enforced when the variable 'https' is set to TRUE. - * - 'base_url': Only used internally, to modify the base URL when a language - * dependent URL requires so. - * - 'prefix': Only used internally, to modify the path when a language - * dependent URL requires so. - * - 'script': Added to the URL between the base path and the path prefix. - * Defaults to empty string when clean URLs are in effect, and to - * 'index.php/' when they are not. - * - 'entity_type': The entity type of the object that called url(). Only - * set if url() is invoked by Drupal\Core\Entity\Entity::uri(). - * - 'entity': The entity object (such as a node) for which the URL is being - * generated. Only set if url() is invoked by Drupal\Core\Entity\Entity::uri(). - * - * @return - * A string containing a URL to the given path. - * - * @throws \Drupal\Core\Routing\GeneratorNotInitializedException. - * - * @deprecated since version 8.0 - * System paths should not be used - use route names and parameters. - */ - public function generateFromPath($path = NULL, $options = array()); - - /** - * Gets the internal path of a route. - * - * @param string $name - * The route name. - * @param array $parameters - * An array of parameters as passed to - * \Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate(). - * - * @return string - * The internal Drupal path corresponding to the route. - * - * @deprecated since version 8.0 - * System paths should not be used - use route names and parameters. - */ - public function getPathFromRoute($name, $parameters = array()); - - /** - * Generates a URL or path for a specific route based on the given parameters. - * - * Parameters that reference placeholders in the route pattern will be - * substituted for them in the pattern. Extra params are added as query - * strings to the URL. - * - * @param string $name - * The name of the route - * @param array $parameters - * An associative array of parameter names and values. - * @param array $options - * (optional) An associative array of additional options, with the following - * elements: - * - 'query': An array of query key/value-pairs (without any URL-encoding) - * to append to the URL. Merged with the parameters array. - * - 'fragment': A fragment identifier (named anchor) to append to the URL. - * Do not include the leading '#' character. - * - 'absolute': Defaults to FALSE. Whether to force the output to be an - * absolute link (beginning with http:). Useful for links that will be - * displayed outside the site, such as in an RSS feed. - * - 'language': An optional language object used to look up the alias - * for the URL. If $options['language'] is omitted, the language will be - * obtained from language(Language::TYPE_URL). - * - 'https': Whether this URL should point to a secure location. If not - * defined, the current scheme is used, so the user stays on HTTP or HTTPS - * respectively. if mixed mode sessions are permitted, TRUE enforces HTTPS - * and FALSE enforces HTTP. - * - * @return string - * The generated URL for the given route. - * - * @throws RouteNotFoundException If the named route doesn't exist - * @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route - * @throws InvalidParameterException When a parameter value for a placeholder is not correct because - * it does not match the requirement - */ - public function generateFromRoute($name, $parameters = array(), $options = array()); - - /** - * Sets the $request property. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The HttpRequest object representing the current request. - */ - public function setRequest(Request $request); - - /** - * Sets the baseUrl property. - * - * This property is made up of scheme, host and base_path, e.g. - * 'http://www.example.com/mydrupalinstall/' - * - * The base url is usually set by the request but we allow it to be set - * independent of the request so that code that calls url() outside the context - * of a request can use the global $base_url variable to set this value. - * - * @todo Remove this once the url() function no longer supports being called - * when there is no request. - * - * @var string $url - * The base url to use for url generation. - */ - public function setBaseUrl($url); - - /** - * Sets the basePath property. - * - * This will be either '/' or '[subdir]/', where [subdir] is the name of the - * subdirectory that Drupal is running in. - * - * The base path is usually set by the request but we allow it to be set - * independent of the request so that code that calls url() outside the context - * of a request can use the global $base_url variable to set this value. - * - * @todo Remove this once the url() function no longer supports being called - * when there is no request. - * - * @var string $path - * The base path to use for url generation. - */ - public function setBasePath($path); - - /** - * Sets the scriptPath property. - * - * The script path is usually set by the request and is either 'index.php' or - * the empty string, depending on whether the request path actually contains - * the script path or not. We allow it to be set independent of the request so - * that code that calls url() outside the context of a request can use the global - * $script_path variable to set this value. - * - * @todo Remove this once the url() function no longer supports being called - * when there is no request. - * - * @var string $path - * The script path to use for url generation. - */ - public function setScriptPath($path); - -} diff --git a/core/modules/action/lib/Drupal/action/Plugin/Action/GotoAction.php b/core/modules/action/lib/Drupal/action/Plugin/Action/GotoAction.php index cf4c3234e036e885f44ffc9b86c30da2166079df..fd158fb24ebbba6c06f2e3a65036ac90c0766523 100644 --- a/core/modules/action/lib/Drupal/action/Plugin/Action/GotoAction.php +++ b/core/modules/action/lib/Drupal/action/Plugin/Action/GotoAction.php @@ -11,7 +11,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Action\ConfigurableActionBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Routing\PathBasedGeneratorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -38,7 +38,7 @@ class GotoAction extends ConfigurableActionBase implements ContainerFactoryPlugi /** * The url generator service. * - * @var \Drupal\Core\Routing\UrlGeneratorInterface + * @var \Drupal\Core\Routing\PathBasedGeneratorInterface */ protected $urlGenerator; @@ -53,10 +53,10 @@ class GotoAction extends ConfigurableActionBase implements ContainerFactoryPlugi * The plugin implementation definition. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher * The tempstore factory. - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator + * @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator * The url generator service. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, EventDispatcherInterface $dispatcher, UrlGeneratorInterface $url_generator) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, EventDispatcherInterface $dispatcher, PathBasedGeneratorInterface $url_generator) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->dispatcher = $dispatcher; diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php index b6a2d84e1ca9025d0551d1a5356e769af8f668ff..ea17112720d5a524a98e60cfb6ed5231c57286ea 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php @@ -13,7 +13,7 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Routing\PathBasedGeneratorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -55,7 +55,7 @@ class AggregatorController implements ControllerInterface { /** * The url generator. * - * @var \Drupal\Core\Routing\UrlGeneratorInterface + * @var \Drupal\Core\Routing\PathBasedGeneratorInterface */ protected $urlGenerator; @@ -73,7 +73,7 @@ class AggregatorController implements ControllerInterface { * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. */ - public function __construct(EntityManager $entity_manager, Connection $database, ConfigFactory $config_factory, ModuleHandlerInterface $module_handler, UrlGeneratorInterface $url_generator) { + public function __construct(EntityManager $entity_manager, Connection $database, ConfigFactory $config_factory, ModuleHandlerInterface $module_handler, PathBasedGeneratorInterface $url_generator) { $this->entityManager = $entity_manager; $this->database = $database; $this->configFactory = $config_factory; diff --git a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php index a75dbca9a11d4565902d4175d3ed825d8d8909ba..4d1af2518fd991d467b30e1a652abf11bbd68dc3 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php @@ -10,7 +10,7 @@ use Drupal\comment\CommentInterface; use Drupal\comment\Entity\Comment; use Drupal\Core\Controller\ControllerInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Routing\PathBasedGeneratorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -28,7 +28,7 @@ class CommentController implements ControllerInterface { /** * The url generator service. * - * @var \Drupal\Core\Routing\UrlGeneratorInterface + * @var \Drupal\Core\Routing\PathBasedGeneratorInterface */ protected $urlGenerator; @@ -42,12 +42,12 @@ class CommentController implements ControllerInterface { /** * Constructs a CommentController object. * - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator + * @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator * The url generator service. * @param \Symfony\Component\HttpKernel\HttpKernelInterface $httpKernel * HTTP kernel to handle requests. */ - public function __construct(UrlGeneratorInterface $url_generator, HttpKernelInterface $httpKernel) { + public function __construct(PathBasedGeneratorInterface $url_generator, HttpKernelInterface $httpKernel) { $this->urlGenerator = $url_generator; $this->httpKernel = $httpKernel; } diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigSync.php b/core/modules/config/lib/Drupal/config/Form/ConfigSync.php index 2cd58541088064ee469d72282ede651a70717793..463590e80d6e7fdbff19e84afbf3ac16d1dff92f 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigSync.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigSync.php @@ -15,7 +15,7 @@ use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Config\ConfigException; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Routing\PathBasedGeneratorInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -65,7 +65,7 @@ class ConfigSync extends FormBase { /** * URL generator service. * - * @var \Drupal\Core\Routing\UrlGeneratorInterface + * @var \Drupal\Core\Routing\PathBasedGeneratorInterface */ protected $urlGenerator; @@ -84,10 +84,10 @@ class ConfigSync extends FormBase { * Configuration object factory. * @param \Drupal\Core\Entity\EntityManager $entity_manager * Entity manager. - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator + * @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator * The url generator service. */ - public function __construct(StorageInterface $sourceStorage, StorageInterface $targetStorage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigFactory $config_factory, EntityManager $entity_manager, UrlGeneratorInterface $url_generator) { + public function __construct(StorageInterface $sourceStorage, StorageInterface $targetStorage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigFactory $config_factory, EntityManager $entity_manager, PathBasedGeneratorInterface $url_generator) { $this->sourceStorage = $sourceStorage; $this->targetStorage = $targetStorage; $this->lock = $lock; diff --git a/core/modules/image/lib/Drupal/image/ImageStyleListController.php b/core/modules/image/lib/Drupal/image/ImageStyleListController.php index 014ab1ff46303b9f435a57ff61acb653848b4c4f..a6f489ef3347aaf83baf5c615435b634fef9b456 100644 --- a/core/modules/image/lib/Drupal/image/ImageStyleListController.php +++ b/core/modules/image/lib/Drupal/image/ImageStyleListController.php @@ -12,7 +12,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Routing\PathBasedGeneratorInterface; use Drupal\Core\StringTranslation\Translator\TranslatorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -24,7 +24,7 @@ class ImageStyleListController extends ConfigEntityListController implements Ent /** * The URL generator. * - * @var \Drupal\Core\Routing\UrlGeneratorInterface + * @var \Drupal\Core\Routing\PathBasedGeneratorInterface */ protected $urlGenerator; @@ -46,12 +46,12 @@ class ImageStyleListController extends ConfigEntityListController implements Ent * The image style entity storage controller class. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke hooks on. - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator + * @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator * The URL generator. * @param \Drupal\Core\StringTranslation\Translator\TranslatorInterface $translator * The translation manager. */ - public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $image_style_storage, ModuleHandlerInterface $module_handler, UrlGeneratorInterface $url_generator, TranslatorInterface $translator) { + public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $image_style_storage, ModuleHandlerInterface $module_handler, PathBasedGeneratorInterface $url_generator, TranslatorInterface $translator) { parent::__construct($entity_type, $entity_info, $image_style_storage, $module_handler); $this->urlGenerator = $url_generator; $this->translator = $translator; diff --git a/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php index 71bbd6c9045c5e68ad497608ed099cc86c4be0f3..7d95e3a851864b3c3fb5ddbcf041620b92662970 100644 --- a/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php +++ b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php @@ -7,7 +7,7 @@ namespace Drupal\locale\Controller; use Drupal\Core\Controller\ControllerInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Routing\PathBasedGeneratorInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -29,7 +29,7 @@ class LocaleController implements ControllerInterface { * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. */ - public function __construct(ModuleHandlerInterface $module_handler, UrlGeneratorInterface $url_generator) { + public function __construct(ModuleHandlerInterface $module_handler, PathBasedGeneratorInterface $url_generator) { $this->moduleHandler = $module_handler; $this->urlGenerator = $url_generator; } diff --git a/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php b/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php index d5fa9b81dde60ccbcdc6d99baf59e11c87e4c3fb..e90f1ea0b6e401a85258f181039b679f427acf85 100644 --- a/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php +++ b/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php @@ -9,8 +9,9 @@ use Drupal\Core\Entity\EntityNGConfirmFormBase; use Drupal\Core\Entity\EntityStorageControllerInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Routing\PathBasedGeneratorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; /** * Provides a form for deleting a node. @@ -20,7 +21,7 @@ class NodeDeleteForm extends EntityNGConfirmFormBase { /** * The URL generator. * - * @var \Drupal\Core\Routing\UrlGeneratorInterface + * @var \Drupal\Core\Routing\PathBasedGeneratorInterface */ protected $urlGenerator; @@ -34,12 +35,12 @@ class NodeDeleteForm extends EntityNGConfirmFormBase { /** * Constructs a NodeDeleteForm object. * - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator + * @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator * The URL generator. * @param \Drupal\Core\Entity\EntityStorageControllerInterface $node_type_storage * The node type storage. */ - public function __construct(UrlGeneratorInterface $url_generator, EntityStorageControllerInterface $node_type_storage) { + public function __construct(PathBasedGeneratorInterface $url_generator, EntityStorageControllerInterface $node_type_storage) { $this->urlGenerator = $url_generator; $this->nodeTypeStorage = $node_type_storage; } diff --git a/core/modules/node/lib/Drupal/node/NodeTypeListController.php b/core/modules/node/lib/Drupal/node/NodeTypeListController.php index 530ccf79838d9c485df362add1bbf49a5e1cff3e..a41051f7c4a7b07bb7f71dfc6f49353a4fdb7b5d 100644 --- a/core/modules/node/lib/Drupal/node/NodeTypeListController.php +++ b/core/modules/node/lib/Drupal/node/NodeTypeListController.php @@ -11,7 +11,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Routing\PathBasedGeneratorInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Component\Utility\Xss; use Drupal\Component\Utility\String; @@ -24,7 +24,7 @@ class NodeTypeListController extends ConfigEntityListController implements Entit /** * The url generator service. * - * @var \Drupal\Core\Routing\UrlGeneratorInterface + * @var \Drupal\Core\Routing\PathBasedGeneratorInterface */ protected $urlGenerator; @@ -39,10 +39,10 @@ class NodeTypeListController extends ConfigEntityListController implements Entit * The entity storage controller class. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke hooks on. - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator + * @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator * The url generator service. */ - public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $storage, ModuleHandlerInterface $module_handler, UrlGeneratorInterface $url_generator) { + public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $storage, ModuleHandlerInterface $module_handler, PathBasedGeneratorInterface $url_generator) { parent::__construct($entity_type, $entity_info, $storage, $module_handler); $this->urlGenerator = $url_generator; } diff --git a/core/modules/overlay/lib/Drupal/overlay/EventSubscriber/OverlaySubscriber.php b/core/modules/overlay/lib/Drupal/overlay/EventSubscriber/OverlaySubscriber.php index b4ba6fdef583df66285dff270594931fd80b61b5..8b8e49dcf115ca99eae3ab8b16b7eb05a56d5bd6 100644 --- a/core/modules/overlay/lib/Drupal/overlay/EventSubscriber/OverlaySubscriber.php +++ b/core/modules/overlay/lib/Drupal/overlay/EventSubscriber/OverlaySubscriber.php @@ -8,7 +8,7 @@ namespace Drupal\overlay\EventSubscriber; use Drupal\Core\ContentNegotiation; -use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Routing\PathBasedGeneratorInterface; use Drupal\user\UserData; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -38,7 +38,7 @@ class OverlaySubscriber implements EventSubscriberInterface { /** * The url generator service. * - * @var \Drupal\Core\Routing\UrlGeneratorInterface + * @var \Drupal\Core\Routing\PathBasedGeneratorInterface */ protected $urlGenerator; @@ -49,10 +49,10 @@ class OverlaySubscriber implements EventSubscriberInterface { * The content negotiation service. * @param \Drupal\user\UserData $user_data * The user.data service. - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator + * @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator * The url generator service. */ - public function __construct(ContentNegotiation $negotiation, UserData $user_data, UrlGeneratorInterface $url_generator) { + public function __construct(ContentNegotiation $negotiation, UserData $user_data, PathBasedGeneratorInterface $url_generator) { $this->negotiation = $negotiation; $this->userData = $user_data; $this->urlGenerator = $url_generator; diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php index 75d051dea8bb57d047c0891de7c00580dd0703d1..d6006ad3388efb2e539c5348c39cff124cec677f 100644 --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php @@ -37,13 +37,6 @@ class UrlGeneratorTest extends UnitTestCase { */ protected $generator; - /** - * A second url generator to test, set to assume mixed-mode sessions. - * - * @var \Drupal\Core\Routing\UrlGenerator - */ - protected $generatorMixedMode; - protected $aliasManager; public static function getInfo() { @@ -72,29 +65,33 @@ function setUp() { ->getMock(); // We need to set up return value maps for both the getRouteByName() and the // getRoutesByNames() method calls on the route provider. The parameters - // are not passed in and default to an empty array. + // passed in will be slightly different but based on the same information. $route_name_return_map = $routes_names_return_map = array(); $return_map_values = array( array( 'route_name' => 'test_1', + 'parameters' => array(), 'return' => $first_route, ), array( 'route_name' => 'test_2', + 'parameters' => array('narf' => '5'), 'return' => $second_route, ), array( 'route_name' => 'test_3', + 'parameters' => array(), 'return' => $third_route, ), array( 'route_name' => 'test_4', + 'parameters' => array(), 'return' => $fourth_route, ), ); foreach ($return_map_values as $values) { - $route_name_return_map[] = array($values['route_name'], array(), $values['return']); - $routes_names_return_map[] = array(array($values['route_name']), array(), $values['return']); + $route_name_return_map[] = array($values['route_name'], $values['parameters'], $values['return']); + $routes_names_return_map[] = array(array($values['route_name']), $values['parameters'], $values['return']); } $provider->expects($this->any()) ->method('getRouteByName') @@ -125,12 +122,8 @@ function setUp() { $generator = new UrlGenerator($provider, $processor_manager, $config_factory_stub, new Settings(array())); $generator->setContext($context); - $this->generator = $generator; - // Second generator for mixed-mode sessions. - $generator = new UrlGenerator($provider, $processor_manager, $config_factory_stub, new Settings(array('mixed_mode_sessions' => TRUE))); - $generator->setContext($context); - $this->generatorMixedMode = $generator; + $this->generator = $generator; } /** @@ -163,10 +156,6 @@ public function testAliasGeneration() { $url = $this->generator->generate('test_1'); $this->assertEquals('/hello/world', $url); - // Check that the two generate methods return the same result. - $url_from_route = $this->generator->generateFromRoute('test_1'); - $this->assertEquals($url_from_route, $url); - $path = $this->generator->getPathFromRoute('test_1'); $this->assertEquals('test/one', $path); } @@ -186,20 +175,7 @@ public function testGetPathFromRouteWithSubdirectory() { */ public function testAliasGenerationWithParameters() { $url = $this->generator->generate('test_2', array('narf' => '5')); - $this->assertEquals('/goodbye/cruel/world', $url); - - $options = array('fragment' => 'top'); - // Extra parameters should appear in the query string. - $url = $this->generator->generateFromRoute('test_1', array('zoo' => '5'), $options); - $this->assertEquals('/hello/world?zoo=5#top', $url); - - $options = array('query' => array('page' => '1'), 'fragment' => 'bottom'); - $url = $this->generator->generateFromRoute('test_2', array('narf' => '5'), $options); - $this->assertEquals('/goodbye/cruel/world?page=1#bottom', $url); - - // Changing the parameters, the route still matches but there is no alias. - $url = $this->generator->generateFromRoute('test_2', array('narf' => '7'), $options); - $this->assertEquals('/test/two/7?page=1#bottom', $url); + $this->assertEquals('/goodbye/cruel/world', $url, 'Correct URL generated including alias and parameters.'); $path = $this->generator->getPathFromRoute('test_2', array('narf' => '5')); $this->assertEquals('test/two/5', $path); @@ -219,11 +195,6 @@ public function testGetPathFromRouteTrailing() { public function testAbsoluteURLGeneration() { $url = $this->generator->generate('test_1', array(), TRUE); $this->assertEquals('http://localhost/hello/world', $url); - - $options = array('absolute' => TRUE, 'fragment' => 'top'); - // Extra parameters should appear in the query string. - $url = $this->generator->generateFromRoute('test_1', array('zoo' => '5'), $options); - $this->assertEquals('http://localhost/hello/world?zoo=5#top', $url); } /** @@ -232,15 +203,6 @@ public function testAbsoluteURLGeneration() { public function testUrlGenerationWithHttpsRequirement() { $url = $this->generator->generate('test_4', array(), TRUE); $this->assertEquals('https://localhost/test/four', $url); - - $options = array('absolute' => TRUE, 'https' => TRUE); - // Mixed-mode sessions are not enabled, so the https option is ignored. - $url = $this->generator->generateFromRoute('test_1', array(), $options); - $this->assertEquals('http://localhost/hello/world', $url); - - // Mixed-mode sessions are enabled, so the https option is obeyed. - $url = $this->generatorMixedMode->generateFromRoute('test_1', array(), $options); - $this->assertEquals('https://localhost/hello/world', $url); } /**