function PathMatcher::isFrontPage

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Path/PathMatcher.php \Drupal\Core\Path\PathMatcher::isFrontPage()
  2. 10 core/lib/Drupal/Core/Path/PathMatcher.php \Drupal\Core\Path\PathMatcher::isFrontPage()
  3. 11.x core/lib/Drupal/Core/Path/PathMatcher.php \Drupal\Core\Path\PathMatcher::isFrontPage()

Overrides PathMatcherInterface::isFrontPage

File

core/lib/Drupal/Core/Path/PathMatcher.php, line 91

Class

PathMatcher
Provides a path matcher.

Namespace

Drupal\Core\Path

Code

public function isFrontPage() {
    // Cache the result as this is called often.
    if (!isset($this->isCurrentFrontPage)) {
        $this->isCurrentFrontPage = FALSE;
        // Ensure that the code can also be executed when there is no active
        // route match, like on exception responses.
        if ($this->routeMatch
            ->getRouteName()) {
            $url = Url::fromRouteMatch($this->routeMatch);
            $this->isCurrentFrontPage = $url->getRouteName() && '/' . $url->getInternalPath() === $this->getFrontPagePath();
        }
    }
    return $this->isCurrentFrontPage;
}

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