Problem/Motivation
Setting a placeholder text to prompt users to use the <input> of a search block is a common end-user facing task. However, right now, the only way to set such value is through a hook.
It would be ideal to have an option in the search block configuration to change this value and the similarly used title.
Steps to reproduce
Add a Search Block to any Drupal site. The "placeholder" text can't be changed without coding a hook or other custom solution.
Proposed resolution
Add the mentioned options as configurable items in the block configuration itself.
Remaining tasks
- Get usability team blessing
- Write change record
- Add config upgrade path
User interface changes
Would add two new configurable items to Search Blocks
API changes
NA
Data model changes
NA
Release notes snippet
Search Blocks now provide an option to configure the placeholder and title text for the query input.
Issue fork drupal-760182
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
Pimmy commentedSmall correction: The second code snippet is from [search.module] file.
Comment #2
jhodgdonFor future reference: an issue gets set to "needs review" after you have created a patch file.
Also, at this point, feature requests are Drupal 8 material. It is past the deadline for Drupal 7.
But I actually don't think we would consider this idea for Drupal core. It's easily accomplished with hook_form_alter() in a contributed module, and we don't use this pattern in other Drupal forms.
With regards for this particular code:
- If it were to be added to Drupal core, the default text would need to be something other than "Search me".
- The default would need to be enclosed in the t() function.
- Form element titles do not end in ":"
- We try not to abbreviate variables. So it should be 'search_teaser_string' not 'str'.
- Also, the word "teaser" has a different meaning in Drupal. So it should be renamed as something else, not teaser.
- We don't add "OnClick" directly to forms, but via standard Drupal JavaScript methods.
Comment #3
Pimmy commentedThanks very much for the thorough explanation. I am pretty green in Drupal, and I still dont know how hook_form_alter() works, but I will dig out.
Anyway, I will take your comments into account and will correct what I've done so far. One thing though - I read (unfortunately cannot fine the source again) that in Drupal 7 the t() function is obsolete as the translation happens automatically by default. Is this wrong?
Thanks once again.
Cheers,
Pimmy
Comment #4
jhodgdonI'm not sure where you read that. t() is alive and well in Drupal 7. There are a few spots where certain hooks ask you to put non-translated information, and it's automatically passed through t() for you, but t() is most certainly still the translation function.
If you would like some evidence:
http://api.drupal.org/api/function/t/7
Scroll down to the bottom and you'll see there are over 1000 calls to t() just in the Drupal core code base. :)
Comment #5
Pimmy commentedCool, I am now more determined to find where I read this. If I come across it again, I will paste the information you've provided here.
Thanks very much for the prompt and thorough responses.
Cheers,
Pimmy
Comment #6
David_Rothstein commentedI think this might be a common enough need that it's worth reopening. (Try searching the internet for "drupal search placeholder" and you can see there are tons of people trying to do this.)
It can be done with a form_alter, but that is not super-clean and it it seems like this is something a site administrator might want to configure. Also, there is now an installation profile in core which adds this text too (see #2937636: Umami Theme - follow-up - Use hook_form_alter() for search block placeholder).
These days, we'd do this with a
placeholderattribute (not JavaScript), which is one reason I marked this for an issue summary update. The current search block has a hardcodedtitleattribute ("Enter the terms you wish to search for") but noplaceholderattribute.This could probably actually be made configurable on the block configuration form itself.
Comment #14
dqdIs this issue still in need or deprecated in favor of another attempt/solution? I think not configurable placeholders is still a missing configuration option especially for multilingual sites. Let me know if I miss something or of we should gain forces here. Set it to Needs review to gain temp. attention for the question. Feel free to set it back to Active or to Needs work or something else regarding the way it should go and if you can give some thoughts on it. Thanks!
Comment #17
smustgrave commentedSeems like the path forward that would need to happen
Will need test coverage as well when implemented.
Comment #22
diegoe commentedAttached MR adds the option of configuring the title and placeholder HTML properties for search block forms.
A new test is included and as many dependents as I noticed (umami, olivero, help) have been updated.
Also: I'm not entirely sure if passing the configuration to
getFormis the cleanest thing but I also couldn't see an obvious reason to frown upon it, sincepage_idis already being passed.I'm a little confused about how/where to set a fallback default, I simply chose a place and ran with it. Hopefully I wasn't _that_ far off.
Comment #23
smustgrave commentedBelieve issue summary still needs to be updated, recommend using standard issue template.
New configuration will require an upgrade path for existing sites. Also a change record.
For the new changes probably will need usability team to take a look
Thanks
Comment #24
diegoe commentedUpdated summary and removed corresponding tag.
How would I go about getting the usability team's review on this?
Comment #26
quietone commentedThe Search Module was approved for removal in #3476883: [Policy, no patch] Move Search module to contrib .
This is Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.
The deprecation work is in #3565780: [meta] Tasks to deprecate the Search module and the removal work in #3565783: [meta] Tasks to remove the Search module.
Search will be moved to a contributed project before Drupal 12.0.0 is released.
Comment #27
quietone commentedThe Search Module has moved from core to contrib,