2

I am using Drupal 8 and the Search API. I have created a search page using the API and views (basically modified the view that came prebuilt when you install the search API). Everything works as expected when you are on the search page doing a search.

The problem I am having is that I would like to create a search block identical to the one the default Drupal Search creates with the same behaviour. Meaning that when you enter a search term, it redirects you to the search page displaying the search results. I can't figure how to do this (assuming it is possible to do so).

I have created a search block but it wants to display the results of the search in the block itself. I don't know how to make the search block redirect to the search page.

I know when using the default search block you can implement the following hook:

function mytheme_search_box_form_submit($form, &$form_state) {
   $form_state['#redirect'] = 'path of redirect';
}

Is there something similar for the Search API?

  • You would need to hook into the form Views is providing and alter it in the same manner – Kevin Oct 30 '17 at 22:49
  • I think you're over-complicating it - just add an exposed filter to the View, type Search: Fulltext search, then set Exposed form in block under Advanced to "Yes". That'll give you a block you can drop into any region with a search field in a form that submits to the search View – Clive Oct 31 '17 at 1:27
  • @Clive That is what I have done but it doesn't allow you to have the search on the page itself. You can either have a block or you can have the search form appear on the page but not both (that is what I am trying to achieve). – user5013 Oct 31 '17 at 2:33
3

There was a similar question for Drupal 7 Expose a view's filters both in a block, and in the actual view. In Drupal 8 this should be much easier, you can do this in UI:

Place the block Exposed form: search_content-page_1 a second time, now in the region Content above the block Main page content and configure the visibility to show only on pages with the path /search/content.

0

You can create a view page of search and link it like '/search' and use this HTML code to get terms into the search page:

<form action="/search" method="get" id="search-block-form" accept-charset="UTF-8">
<input data-drupal-selector="edit-keys" type="search" id="edit-keys" name="keys" value="" size="15" maxlength="128" class="search"/>
    </form>
0

Just add a complement to the answers for D8

Place the block Exposed form: search_content-page_1 a second time, now in the region Content above the block Main page content and configure the visibility to show only on pages with the path /search/content.

You need to set to YES in you page views in "advanced" tab "Exposed form in block" If you try that with simple block views is not working.enter image description here

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.