function CurrentPathStack::getPath

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Path/CurrentPathStack.php \Drupal\Core\Path\CurrentPathStack::getPath()
  2. 8.9.x core/lib/Drupal/Core/Path/CurrentPathStack.php \Drupal\Core\Path\CurrentPathStack::getPath()
  3. 10 core/lib/Drupal/Core/Path/CurrentPathStack.php \Drupal\Core\Path\CurrentPathStack::getPath()

Returns the path of the current request.

Parameters

\Symfony\Component\HttpFoundation\Request $request: (optional) The request.

Return value

string Returns the path, without leading slashes.

File

core/lib/Drupal/Core/Path/CurrentPathStack.php, line 51

Class

CurrentPathStack
Represents the current path for the current request.

Namespace

Drupal\Core\Path

Code

public function getPath(?Request $request = NULL) {
    if (!isset($request)) {
        $request = $this->requestStack
            ->getCurrentRequest();
    }
    if (!isset($this->paths[$request])) {
        $this->paths[$request] = $request->getPathInfo();
    }
    return $this->paths[$request];
}

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