function SearchPageRepository::getDefaultSearchPage

Same name in other branches
  1. 9 core/modules/search/src/SearchPageRepository.php \Drupal\search\SearchPageRepository::getDefaultSearchPage()
  2. 8.9.x core/modules/search/src/SearchPageRepository.php \Drupal\search\SearchPageRepository::getDefaultSearchPage()
  3. 11.x core/modules/search/src/SearchPageRepository.php \Drupal\search\SearchPageRepository::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;
}

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