Drupal Answers Asked by Tritof on January 6, 2022
So far I have tried this code in mytheme.theme:
function mytheme_form_search_block_form_alter(&$form, DrupalCoreFormFormStateInterface $form_state, $form_id) {
$form['keys']['#attributes']['placeholder'] = t('Custom wording');
}
And this one:
function mytheme_form_alter(&$form, DrupalCoreFormFormStateInterface $form_state, $form_id) {
if ($form_id == 'search_block_form') {
$form['keys']['#attributes']['placeholder'] = t('Custom wording');
}
}
Also this one:
function mytheme_form_search_block_form_alter(&$form, $form_state) {
$form['keys']['#attributes']['placeholder'] = t('Custom wording');
}
Site is not crashing, but nothing happens on the placeholder.
I have based these 3 snippets on these pages:
This code should create the placeholder:
function mytheme_form_search_block_form_alter(&$form, DrupalCoreFormFormStateInterface $form_state, $form_id) {
$form['keys']['#attributes']['placeholder'] = t('The new placeholder');
}
So if that does not work for you, it might be because you need to clear the cache.
Answered by user72672 on January 6, 2022
3 Asked on September 6, 2020 by johntang
1 Asked on September 4, 2020 by vintorg
1 Asked on August 21, 2020 by monkeyuser
2 Asked on August 15, 2020 by kareem
1 Asked on August 4, 2020 by pan-chrono
Get help from others!
Recent Questions
Recent Answers
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir