You are here

public function SearchPageRepository::getDefaultSearchPage in Zircon Profile 8

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

Returns the default search page.

Return value

\Drupal\search\SearchPageInterface|bool The search page entity, or FALSE if no pages are active.

Overrides SearchPageRepositoryInterface::getDefaultSearchPage

File

core/modules/search/src/SearchPageRepository.php, line 77
Contains \Drupal\search\SearchPageRepository.

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;
}