Does not seem to kick in with Search API and Search API Block

Created on 17 November 2024, about 1 month ago

Problem/Motivation

I am using the latest version of Search API Block to place a global Search block. That works perfectly fine and the block looks like this (relatively un-styled) ...

I am then attempting to use this module (Better Search) style it up.

Here is the mark-up of the block that should be being altered...

<div class="search-api-form block block-search-api-block block-search-api-form-block"
  data-drupal-selector="search-api-form" novalidate="novalidate" id="block-bit-by-bit-searchapiform">
  <form data-block="nav_branding" action="/search/student" method="get" id="search-api-form" accept-charset="UTF-8">
    <div
      class="clearfix js-form-item form-item js-form-type-search form-type-search js-form-item-search-api-fulltext form-item-search-api-fulltext form-no-label">
      <label for="edit-search-api-fulltext--2" class="visually-hidden">Search</label>
      <input title="Enter the terms you wish to search for." data-drupal-selector="edit-search-api-fulltext"
        type="search" id="edit-search-api-fulltext--2" name="search_api_fulltext" value="" size="15" maxlength="128"
        placeholder="" class="form-search form-control">
    </div>
    <div data-drupal-selector="edit-actions" class="form-actions js-form-wrapper form-wrapper" id="edit-actions--2">
      <input data-drupal-selector="edit-submit" type="submit" id="edit-submit" value="Search"
        class="button js-form-submit form-submit btn btn-primary btn-sm">
    </div>
  </form>
</div>

I can see clearly that the ID of the block is block-bit-by-bit-searchapiform and the name of the <input> is search_api_fulltext.

I have configured the module (basic) like this...

I have specifically set the block ID and the <input> name too...

The net result is no kicking-in and so not restyling as far as I can see.

Multiple cache-clears, both Drupal, and Browser, CSS aggregation and page caching are OFF.

What I am I missing here?

Thank you

🐛 Bug report
Status

Active

Version

2.0

Component

Miscellaneous

Created by

🇬🇧United Kingdom SirClickALot Somerset

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @SirClickALot
  • 🇧🇭Bahrain Jed_BH

    So, I installed this module today and noticed the same issue. So, I fired up Xdebug and found out that in the module, there is these lines:

    function better_search_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    
      $block_form_id = \Drupal::config('better_search.settings')->get('block_form_id');

    The main issue here is that while the ID being pulled from the settings form, in my case, is = views-exposed-form-search-page-1

    The id being retrieved from $form_id is only = views_exposed_form

    Thus, the evaluation of $form_id against $block_form_id is false.

    So, to rectify this I changed the module lines to:

    function better_search_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    
      $block_form_id = \Drupal::config('better_search.settings')->get('block_form_id');
      $input_name = \Drupal::config('better_search.settings')->get('input_name');
      $full_form_id = isset($form['#id']) ? $form['#id'] : '';
      if ($form_id == $block_form_id || $form_id == 'search_form' || $full_form_id == $block_form_id) {

    I am not confident in this, but it solved the issue of this thread. However, the attached library won't work without further tweaks with my exposed form filter for search_api.

Production build 0.71.5 2024