Theme Overrides for Search Box

Created on 23 February 2023, over 1 year ago

Problem/Motivation

Unable to override the Cludo search input form with a custom theme hook_form_alter().

Aim is to replace the 'Search' text in the button with a CSS image, by removing the text and adding a class to the submit button.

Steps to reproduce

In my THEME.theme file I have the following hook to override the form settings:

function THEME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'cludo_search_block_search_form') {
    if ($form['#id'] == 'cludo-search-block-search-form') {
      //Remove text from Search button and add class. DOESN'T WORK!!
      $form['submit']['#value'] = ""; 
      $form['submit']['#attributes']['class'][] = 'search-button';
    }
  }

Inspecting the $form array and the new values are set (overriding the 'Search' translated text value in 'value', and adding a 'search-button' class)

Just wondering why the overrides aren't working in the theme (they work just fine on a Search API form)? The form is generated at cludo_search/src/Form/CludoSearchBlockForm.php but don't understand why hook_form_alter() isn't working here

💬 Support request
Status

Closed: works as designed

Component

Code

Created by

🇬🇧United Kingdom robcarr Perthshire, Scotland

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

Comments & Activities

  • Issue created by @robcarr
  • Status changed to Closed: works as designed over 1 year ago
  • 🇬🇧United Kingdom robcarr Perthshire, Scotland

    Sorry, my bad. Following override works as designed:

    function THEME_form_alter(&$form, &$form_state, $form_id) {
      if ($form_id == 'cludo_search_block_search_form') {
        //Remove text from Search button and add class
        $form['submit']['#value'] = "";
        $form['submit']['#attributes']['class'][] = 'search-button';
      }
    }
    
Production build 0.71.5 2024