diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index a457e8f..4052411 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -43,13 +43,14 @@ class Url { /** * Scheme for URIs to resolve as references relative to Drupal's installation. * - * https://tools.ietf.org/html/rfc3986#section-5.2 specifies the standard for - * resolving URI references relative to a base URI. + * Use this scheme for linking to pages on the same host as the Drupal site, + * but not generated by Drupal. * - * This scheme is to allow such references to be internally represented and - * managed in Drupal as full URIs themselves, and resolved to the - * corresponding URLs at runtime. When performing this resolution, the base - * URI is Drupal's installation URL. + * https://tools.ietf.org/html/rfc3986#section-5.2 specifies the standard for + * resolving URI references relative to a base URI. This scheme allows such + * references to be internally represented and managed in Drupal as full URIs + * themselves, and resolved to the corresponding URLs at runtime, using + * Drupal's installation URL as the base URI. * * For example, if Drupal is installed in http://example.com/drupal/, then: * - Url::fromUri(Url::SCHEME_BASE . ':README.txt')->toString() would return @@ -70,22 +71,19 @@ class Url { * - Url::fromHostRelativePath('index.html') is equivalent to * Url::fromUri(Url::SCHEME_BASE . ':/index.html'). * - * Note that this scheme is intended for linking to non-Drupal-routed pages. - * For example, to static files or to pages served by other software on the - * website. As such, the resolution of this scheme does not apply any path - * processors, such as language prefixing and alias lookup, or access - * checking (->access() returns TRUE for URIs in this scheme). Therefore, - * using this scheme for Drupal-routed pages is incompatible with - * multilingual sites, with search engine optimization, and with hiding links - * to pages that the user can't access, unless you take care of all that - * yourself. For these reasons, it is recommended to not use this scheme for - * pages served by Drupal. The other schemes and their wrapper methods - * can be used for that. - * - * @see static::fromBaseRelativePath() - * @see static::fromHostRelativePath() - * @see static::fromRoute() - * @see static::fromUri() + * Do not use this scheme for linking to pages generated by Drupal. With this + * scheme, mo path processors are applied (including language prefixes and + * aliases) and no access checking is performed. This means it is + * incompatible with: + * - Multilingual sites + * - Search engine optimization + * - Hiding links the user cannot access + * Use Url::fromRoute() to generate URLs for pages generated by Drupal. + * + * @see \Drupal\Core\Url::fromBaseRelativePath() + * @see \Drupal\Core\Url::fromHostRelativePath() + * @see \Drupal\Core\Url::fromRoute() + * @see \Drupal\Core\Url::fromUri() */ const SCHEME_BASE = 'base'; @@ -95,8 +93,8 @@ class Url { * To create a URL for paths from user input that may or may not correspond * to a valid Drupal route, use Url::fromUserInput(). * - * @see static::fromUserInput() - * @see static::fromUserPathUri() + * @see \Drupal\Core\Url::fromUserInput() + * @see \Drupal\Core\Url::fromUserPathUri() * * @todo Rename this constant depending on the outcome of: * https://www.drupal.org/node/2417567 @@ -111,17 +109,17 @@ class Url { * you should use \Drupal\Core\Entity\Entity::url() rather than creating a * URI directly. * - * @see static::fromEntityUri() + * @see \Drupal\Core\Url::fromEntityUri() */ const SCHEME_ENTITY = 'entity'; /** * Scheme for routed URIs. * - * This scheme is used internally for handling routes as URIs. To get the + * This scheme is used internally for storing routes as URIs. To get the * URL for a route, use Url::fromRoute(). * - * @see static::fromRouteUri() + * @see \Drupal\Core\Url::fromRouteUri() * * @todo What exactly is the point of this scheme? See: * https://www.drupal.org/node/2418139 @@ -243,10 +241,9 @@ public function __construct($route_name, $route_parameters = array(), $options = /** * Creates a new Url object for a URL that has a Drupal route. * - * This method is for URLs that have Drupal routes (that is, most pages - * generated by Drupal). To generate a URL for a route match instead (that - * is, the route corresponding to a particular request), use - * Url::fromRouteMatch(). + * This method is for URLs that have Drupal routes (pages generated by + * Drupal). To generate a URL for a route match instead (that is, the route + * corresponding to a particular request), use Url::fromRouteMatch(). * * @param string $route_name * The name of the route @@ -272,40 +269,39 @@ public function __construct($route_name, $route_parameters = array(), $options = * @return \Drupal\Core\Url * A new Url object for a routed (internal to Drupal) URL. * - * @see static::fromRouteMatch() - * @see static::fromUserInput() - * @see static::fromBaseRelativePath() - * @see static::fromUri() + * @see \Drupal\Core\Url::fromRouteMatch() + * @see \Drupal\Core\Url::fromUserInput() + * @see \Drupal\Core\Url::fromBaseRelativePath() + * @see \Drupal\Core\Url::fromUri() */ public static function fromRoute($route_name, $route_parameters = array(), $options = array()) { return new static($route_name, $route_parameters, $options); } /** - * Creates a new URL object from an unrouted, base-relative path. + * Creates a new Url object from an unrouted, base-relative path. * * This method should only be used for paths within the base directory of the * site installation that do not have a Drupal route. These may be files like - * robots.txt, core scripts like core/install.php, or they may be another - * application placed within the Drupal site installation. + * 'robots.txt', core scripts like 'core/install.php', or they may be from + * another application placed within the Drupal site installation. * - * Do not use this method for URLs that have a Drupal route (that is, most - * pages generated by Drupal). See the documentation of static::SCHEME_BASE - * for details. + * Do not use this method for URLs that have a Drupal route (pages generated + * by Drupal). See the documentation of Url::SCHEME_BASE for details. * * @param string $path * The base-relative path, for example 'robots.txt'. * @param array $options - * (optional) An array of options. See static::fromUri() for details. + * (optional) An array of options. See Url::fromUri() for details. * * @return \Drupal\Core\Url * A new Url object for an unrouted URL within the site installation * directory. * - * @see static::SCHEME_BASE - * @see static::fromHostRelativePath() - * @see static::fromUri() - * @see static::fromRoute() + * @see \Drupal\Core\Url::SCHEME_BASE + * @see \Drupal\Core\Url::fromHostRelativePath() + * @see \Drupal\Core\Url::fromUri() + * @see \Drupal\Core\Url::fromRoute() */ public static function fromBaseRelativePath($path, $options = array()) { return static::fromUri(static::SCHEME_BASE . ':' . $path, $options); @@ -317,25 +313,24 @@ public static function fromBaseRelativePath($path, $options = array()) { * This method should only be used for paths within the same host as the * site installation. * - * Do not use this method for URLs that have a Drupal route (that is, most - * pages generated by Drupal). See the documentation of static::SCHEME_BASE - * for details. + * Do not use this method for URLs that have a Drupal route (pages generated + * by Drupal). See the documentation of Url::SCHEME_BASE for details. * * @param string $path * The host-relative path. For example, if Drupal is installed in the * subdirectory http://example.com/drupal/, use 'index.html' for a URL to * http://example.com/index.html. * @param array $options - * (optional) An array of options. See static::fromUri() for details. + * (optional) An array of options. See Url::fromUri() for details. * * @return \Drupal\Core\Url * A new Url object for an unrouted, host-relative URL not internal to * Drupal, but relative to the site host. * - * @see static::SCHEME_BASE - * @see static::fromBaseRelativePath() - * @see static::fromUri() - * @see static::fromRoute() + * @see \Drupal\Core\Url::SCHEME_BASE + * @see \Drupal\Core\Url::fromBaseRelativePath() + * @see \Drupal\Core\Url::fromUri() + * @see \Drupal\Core\Url::fromRoute() */ public static function fromHostRelativePath($path, $options = array()) { return static::fromUri(static::SCHEME_BASE . ':/' . $path, $options); @@ -344,18 +339,17 @@ public static function fromHostRelativePath($path, $options = array()) { /** * Creates a new Url object from a route match (e.g. for the current request). * - * Use this method to create a URL from a specific route match, that is, - * the route that best corresponds to a particular request. This is often - * used to generate URLs based on the URL for the current request. To - * generate a URL for a specific route (rather than from a request), use - * Url::fromRoute(). + * Use this method to create a URL from a specific route match, that is, the + * route that best corresponds to a particular request. This is often used to + * generate URLs based on the URL for the current request. To generate a URL + * for a specific route (rather than from a request), use Url::fromRoute(). * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match. * * @return $this * - * @see static::fromRoute() + * @see \Drupal\Core\Url::fromRoute() * @see \Drupal\Core\Routing\RouteMatchInterface */ public static function fromRouteMatch(RouteMatchInterface $route_match) { @@ -415,10 +409,10 @@ public static function fromRouteMatch(RouteMatchInterface $route_match) { * @throws \InvalidArgumentException * Thrown when the passed in path has no scheme. * - * @see static::fromRoute() - * @see static::fromUserInput() - * @see static::fromBaseRelativePath() - * @see static::fromHostRelativePath() + * @see \Drupal\Core\Url::fromRoute() + * @see \Drupal\Core\Url::fromUserInput() + * @see \Drupal\Core\Url::fromBaseRelativePath() + * @see \Drupal\Core\Url::fromHostRelativePath() * @see \Drupal\Core\Entity\EntityInterface::url() */ public static function fromUri($uri, $options = []) { @@ -477,7 +471,7 @@ public static function fromUri($uri, $options = []) { * Parts from an URI of the form entity:{entity_type}/{entity_id} as from * parse_url(). * @param array $options - * An array of options, see static::fromUri() for details. + * An array of options, see Url::fromUri() for details. * @param string $uri * The original entered URI. * @@ -530,7 +524,7 @@ protected static function fromEntityUri(array $uri_parts, array $options, $uri) * @param array $uri_parts * Parts from an URI of the form user-path:{path} as from parse_url(). * @param array $options - * An array of options. See static::fromUri() for details. + * An array of options. See Url::fromUri() for details. * * @return \Drupal\Core\Url * A new Url object for a 'user-path:' URI. @@ -570,7 +564,7 @@ protected static function fromUserPathUri(array $uri_parts, array $options) { * from parse_url(), where the path is the route name optionally followed by * a ";" followed by route parameters in key=value format with & separators. * @param array $options - * An array of options. See static::fromUri() for details. + * An array of options. See Url::fromUri() for details. * @param string $uri * The original passed in URI. *