PathMatcher::isFrontPage

public PathMatcher::isFrontPage()

Checks if the current page is the front page.

Return value

bool TRUE if the current page is the front page.

Overrides PathMatcherInterface::isFrontPage

File

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

Class

PathMatcher
Provides a path matcher.

Namespace

Drupal\Core\Path

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
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;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.