You are here

public function SearchPageRepository::getDefaultSearchPage in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/search/src/SearchPageRepository.php \Drupal\search\SearchPageRepository::getDefaultSearchPage()

Returns the default search page.

Return value

string|false The default search page entity ID, or FALSE if no pages are active.

Overrides SearchPageRepositoryInterface::getDefaultSearchPage

File

core/modules/search/src/SearchPageRepository.php, line 72

Class

SearchPageRepository
Provides a repository for Search Page config entities.

Namespace

Drupal\search

Code

public function getDefaultSearchPage() {

  // Find all active search pages (without loading them).
  $search_pages = $this
    ->getQuery()
    ->condition('status', TRUE)
    ->execute();

  // If the default page is active, return it.
  $default = $this->configFactory
    ->get('search.settings')
    ->get('default_page');
  if (isset($search_pages[$default])) {
    return $default;
  }

  // Otherwise, use the first active search page.
  return is_array($search_pages) ? reset($search_pages) : FALSE;
}