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

Command icon 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

Pimmy’s picture

Small correction: The second code snippet is from [search.module] file.

jhodgdon’s picture

Title: Search module - Teaser text » Add configurable text to search box that goes away when the box is clicked
Priority: Minor » Normal
Status: Needs review » Closed (won't fix)

For 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.

Pimmy’s picture

Thanks 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

jhodgdon’s picture

I'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. :)

Pimmy’s picture

Cool, 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

David_Rothstein’s picture

Title: Add configurable text to search box that goes away when the box is clicked » Add configurable placeholder text to search box that goes away when the box is clicked
Version: 7.x-dev » 8.6.x-dev
Status: Closed (won't fix) » Active
Issue tags: +Needs backport to D7, +Needs issue summary update

I 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 placeholder attribute (not JavaScript), which is one reason I marked this for an issue summary update. The current search block has a hardcoded title attribute ("Enter the terms you wish to search for") but no placeholder attribute.

This could probably actually be made configurable on the block configuration form itself.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dqd’s picture

Status: Active » Needs review

Is 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!

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Active
Issue tags: +Needs Review Queue Initiative
The current search block has a hardcoded title attribute ("Enter the terms you wish to search for") but no placeholder attribute.

This could probably actually be made configurable on the block configuration form itself

Seems like the path forward that would need to happen

Will need test coverage as well when implemented.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

diegoe made their first commit to this issue’s fork.

diegoe changed the visibility of the branch 760182_diegoe_search-block-title-and-placeholder to hidden.

diegoe’s picture

Status: Active » Needs review

Attached 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 getForm is the cleanest thing but I also couldn't see an obvious reason to frown upon it, since page_id is 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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs upgrade path, +Needs change record, +Needs usability review

Believe 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

diegoe’s picture

Title: Add configurable placeholder text to search box that goes away when the box is clicked » Make placeholder and title properties configurable in SearchBlock
Issue summary: View changes
Issue tags: -Needs issue summary update

Updated summary and removed corresponding tag.

How would I go about getting the usability team's review on this?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Status: Needs work » Postponed

The 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.

quietone’s picture

Project: Drupal core » Search (from core)
Version: main » 1.0.0
Component: search.module » Code
Status: Postponed » Needs work

The Search Module has moved from core to contrib,