Reported in https://www.drupal.org/project/drupal/issues/2809635#comment-12432197
We have a template input--search.html.twig to add a placeholder. @larowlan suggested this could be a form_alter.
from issue:
=============
+++ b/core/profiles/demo_umami/themes/umami/templates/components/search/input--search.html.twig
@@ -0,0 +1,18 @@
+ set placeholder_text = 'Search by keyword, ingredient, dish'
+%}
+
+{{ children }}
Are we sure doing this globally for the search element is the best option?
Suggest a form_alter in the theme instead and then dropping this template?
=============
Looking at the code, I agree. I don't think what we have in the template is translatable, so we can wrap it in a t('') string in a form_alter.
Comment | File | Size | Author |
---|---|---|---|
#2 | umami_theme-using_form_alter_for_placeholder-2937636-2.patch | 1.66 KB | piyuesh23 |
Comments
Comment #2
piyuesh23 CreditAttribution: piyuesh23 at QED42 commentedMoved Placeholder inside form alter in umami.theme. Uploading the patch here. Also, updating the version number to 8.6.x-dev here, since the profile is committed to 8.6.x now.
Comment #3
piyuesh23 CreditAttribution: piyuesh23 at QED42 commentedComment #4
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedThanks a lot @piyuesh23. Looks ready to be committed.
Comment #5
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedComment #6
catchCommitted 42c9e7b and pushed to 8.6.x. Thanks!
Comment #8
thamasHm, I just do not understand this issue. We worked a lot to make Drupal theming more understandable for non php developers. One thing was to reach this goal to move as much as possible to templates instead of keeping them in php code.
Such a simple thing as creating a variable does not need any form_alter IMHO.
(Missing possibilty of translation in the above code is valid but that can be solved easily in the template too.)
Comment #9
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedWell, this shouldn't really be a theming task to begin with - ideally it would be more of a site configuration task anyway. I reopened this very old Search module issue now for discussion: #760182: Add configurable placeholder text to search box that goes away when the box is clicked