0

What's the best way to remove the search form from the search result page in Drupal 8?

  • Is the form a block? You can disable the path visibility for search result paths. – Kevin Oct 12 '17 at 19:26
  • No, it is not a block. There is a search form that is a block and I have that placed in a region. By default the search results page has a second search form that is not a block and there is no way to hide it from the admin. I don't want to have this second search form. – scuttle-jesuit Oct 12 '17 at 19:28
0

There is not much you can customize in core search. So you probably need to override Drupal\search\Controller\SearchController::view and remove this line:

  $build['search_form'] = $this->formBuilder()->getForm(SearchPageForm::class, $entity);

Put your extended class into the route search.view_node_search in a RouteSubscriber.

But I don't think it's worth the effort. You can either simply hide the form in CSS or if you want a fully customizable search solution use Search API.

| improve this answer | |
-1

I'm not sure if is the best way, but you can remove it from your theme preprocess, just for that page: /** * Implements hook_preprocess_search_api_page() */ function YOURTHEME_preprocess_search_api_page(&$vars) { unset($vars['form']); }

| improve this answer | |
  • This does not appear to work. Using hook_preprocess_HOOK() would be something like YOURTHEME_preprocess_page__search_api(&$vars) {}. That assumes the hook suggestion would be search_api, which I'm not certain it is. Furthermore, I think $vars['form'] would not be the correct array key to unset b/c the form would likely be found within a nested array starting with the page region name as the first key. – Jason May 15 '18 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.