function Drupal::url
Generates a URL string for a specific route based on the given parameters.
This method is a convenience wrapper for generating URL strings for URLs that have Drupal routes (that is, most pages generated by Drupal) using the \Drupal\Core\Url object. See \Drupal\Core\Url::fromRoute() for detailed documentation. For non-routed local URIs relative to the base path (like robots.txt) use Url::fromUri()->toString() with the base: scheme.
Parameters
string $route_name: The name of the route.
array $route_parameters: (optional) An associative array of parameter names and values.
array $options: (optional) An associative array of additional options.
bool $collect_bubbleable_metadata: (optional) Defaults to FALSE. When TRUE, both the generated URL and its associated bubbleable metadata are returned.
Return value
string|\Drupal\Core\GeneratedUrl A string containing a URL to the given path. When $collect_bubbleable_metadata is TRUE, a GeneratedUrl object is returned, containing the generated URL plus bubbleable metadata.
Deprecated
in drupal:8.0.0 and is removed from drupal:9.0.0. Instead create a \Drupal\Core\Url object directly, for example using Url::fromRoute().
See also
\Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute()
1 call to Drupal::url()
- DrupalTest::testUrl in core/
tests/ Drupal/ Tests/ Core/ DrupalTest.php - Tests the url() method.
File
-
core/
lib/ Drupal.php, line 589
Class
- Drupal
- Static Service Container wrapper.
Code
public static function url($route_name, $route_parameters = [], $options = [], $collect_bubbleable_metadata = FALSE) {
@trigger_error('Drupal::url() is deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Instead create a \\Drupal\\Core\\Url object directly, for example using Url::fromRoute()', E_USER_DEPRECATED);
return static::getContainer()->get('url_generator')
->generateFromRoute($route_name, $route_parameters, $options, $collect_bubbleable_metadata);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.