1

So far I have tried this code in mytheme.theme:

function mytheme_form_search_block_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
    $form['keys']['#attributes']['placeholder'] = t('Custom wording');
}

And this one:

function mytheme_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $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:

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.