Problem/Motivation

It is difficult to theme the inputs in this form separately from other search forms.
I'd like to be able to add a unique theme suggestion to both the search input and the submit button.

The default theme hook for the search input is input__search
and the default theme hook for the search submit input is input__submit

These are the same as any other search input which may be on the page.

Steps to reproduce

The theme_hook_original can be seen in $variables inside a hook_theme_suggestions_input_alter()

Proposed resolution

There is an open issue to add "context" to form elements, see #2511548: Add a "context" array variable to all theme hooks and "#context" array property to all elements to provide optional contextual data

However in the meantime adding another suggestion to the form elements here would make it easier to theme these inputs separately from any other submit or input type="search".

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#3 search_api_block-3338779-3.patch1.68 KBphjou
#2 3249813-2.patch1.41 KBzrpnr

Comments

zrpnr created an issue. See original summary.

zrpnr’s picture

Status: Active » Needs review
StatusFileSize
new1.41 KB

This patch adds a variable to the inputs directly in the form, as well as an implementation of hook_theme_suggestions_input_alter to add a theme suggestion.

This feels a little kludgy but it makes it very easy to add template overrides or preprocess functions that directly target these elements into a theme.

For example: mytheme_preprocess_input__search__search_api_block

I deliberately picked a very obvious property #search_api_block rather than using #context
Since that may land in #2511548: Add a "context" array variable to all theme hooks and "#context" array property to all elements to provide optional contextual data

I'm very open to a better idea for adding information to these inputs to distinguish them from other form elements, but this seemed like a simple and harmless approach, let me know what you think :)

phjou’s picture

StatusFileSize
new1.68 KB

It seems like a good solution to me.

It is already possible to achieve that with custom code using hook_form_alter and hook_theme_suggestions_HOOK_alter. But I agree that this code is pretty small and can help developers spending less time on trying to customize.

I rerolled your patch because it was not applying anymore.

  • phjou committed dc93123f on 1.0.x
    Issue #3249813 by zrpnr, phjou: Add theme suggestions for form elements
    
phjou’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.