diff --git a/core/modules/search/src/Form/SearchBlockForm.php b/core/modules/search/src/Form/SearchBlockForm.php index 4edcd73..f3a7a8c 100644 --- a/core/modules/search/src/Form/SearchBlockForm.php +++ b/core/modules/search/src/Form/SearchBlockForm.php @@ -77,6 +77,7 @@ public function getFormId() { */ public function buildForm(array $form, FormStateInterface $form_state, $entity_id = NULL) { // Set up the form to submit using GET to the correct search page. + // But first, make sure this search page is active. if (!$entity_id) { $entity_id = $this->searchPageRepository->getDefaultSearchPage(); // SearchPageRepository::getDefaultSearchPage() depends on @@ -87,7 +88,12 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_i $this->renderer->addCacheableDependency($form, $this->configFactory->get('search.settings')); } - if (!$entity_id) { + if ($entity_id) { + $pages = $this->searchPageRepository->getActiveSearchPages(); + $entity = $pages[$entity_id] ?? NULL; + } + + if (!isset($entity)) { $form['message'] = [ '#markup' => $this->t('Search is currently disabled'), ]; diff --git a/core/modules/search/src/SearchPageRepositoryInterface.php b/core/modules/search/src/SearchPageRepositoryInterface.php index 6169fbc..7ed5d43 100644 --- a/core/modules/search/src/SearchPageRepositoryInterface.php +++ b/core/modules/search/src/SearchPageRepositoryInterface.php @@ -34,8 +34,8 @@ public function getIndexableSearchPages(); /** * Returns the default search page. * - * @return \Drupal\search\SearchPageInterface|bool - * The search page entity, or FALSE if no pages are active. + * @return string|false + * The default search page entity ID, or FALSE if no pages are active. */ public function getDefaultSearchPage();