2

I am trying to modify the form action of the search block in my Drupal 8 project. The search block is placed in the Primary menu area. I added the following code in my .theme file

function mytheme_form_alter(&$form, FormStateInterface $form_state, $form_id) {
echo 'my search form'.$form_id; 
}

This form alter is not called when the page is loaded.

I tried adding form_alter in my custom module. It is also not working. Any ideas?

Pramod Sivadas
  • 873
  • 2
  • 9
  • 28

2 Answers2

-1

I found the answer. We can change the form action in block--search.html.twig file in the theme folder.

Pramod Sivadas
  • 873
  • 2
  • 9
  • 28
-1

You cannot use hook_form_alter in the theme, only in the modules

Denis Viunyk
  • 101
  • 2