function UrlGenerator::getPathFromRoute

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Routing/UrlGenerator.php \Drupal\Core\Routing\UrlGenerator::getPathFromRoute()
  2. 8.9.x core/lib/Drupal/Core/Routing/UrlGenerator.php \Drupal\Core\Routing\UrlGenerator::getPathFromRoute()
  3. 11.x core/lib/Drupal/Core/Routing/UrlGenerator.php \Drupal\Core\Routing\UrlGenerator::getPathFromRoute()

Gets the internal path (system path) for a route.

Parameters

string|\Symfony\Component\Routing\Route $name: The route name or a route object.

array $parameters: An array of parameters as passed to \Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate().

Return value

string The internal Drupal path corresponding to the route. This string is not urlencoded and will be an empty string for the front page.

Overrides UrlGeneratorInterface::getPathFromRoute

File

core/lib/Drupal/Core/Routing/UrlGenerator.php, line 131

Class

UrlGenerator
Generates URLs from route names and parameters.

Namespace

Drupal\Core\Routing

Code

public function getPathFromRoute($name, $parameters = []) {
  $route = $this->getRoute($name);
  if (!is_string($name)) {
    @trigger_error('Passing a route object to ' . __METHOD__ . '() is deprecated in drupal:10.1.0 and will not be supported in drupal:11.0.0. Pass the route name instead. See https://www.drupal.org/node/3172280', E_USER_DEPRECATED);
    $name = $this->getRouteStringIdentifier($name);
  }
  $this->processRoute($name, $route, $parameters);
  $path = $this->getInternalPathFromRoute($name, $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
  // is handled in processPath().
  $path = preg_replace('/\\?.*/', '', $path);
  return trim($path, '/');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.