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
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | search_api_block-3338779-3.patch | 1.68 KB | phjou |
| #2 | 3249813-2.patch | 1.41 KB | zrpnr |
Comments
Comment #2
zrpnrThis 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_blockI deliberately picked a very obvious property
#search_api_blockrather than using#contextSince 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 :)
Comment #3
phjouIt 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.
Comment #5
phjou