How do I find the search block form ID? I added some search block in my theme, and I placed each of them in a custom place.
I want to edit each of theme by using function hook_form_FORM_ID_alter for this purpose.


  Provide a form-specific alteration instead of the global
  hook_form_alter().
  
  Modules can implement hook_form_FORM_ID_alter() to modify a specific
  form, rather than implementing hook_form_alter() and checking the form
  ID, or using long switch statements to alter multiple forms.


How can I find each search block form ID? How can I edit them in ThemeName_form_search_block_form_alter() to add special classes to each of them?

I used the Devel module for this purpose, but It seems that for the Devel module, all those forms have the same ID (search_block_form).

This is the code I used.

function ThemeName_form_search_block_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  drupal_set_message(kint($form));
  $form['keys']['#attributes']['placeholder'][] = t('Search');
  $form['actions']['submit']['#attributes']['class'][] = 'my-class';
}
The first thing to do is extend SearchBlockForm so you can give it a custom ID. Put code in mymodule/src/Form/MymoduleSearchBlockForm.php

namespace Drupal\mymodule\Form;

use Drupal\search\Form\SearchBlockForm;

class MymoduleSearchBlockForm extends SearchBlockForm
{
  protected $formIdentifier;

  public function setFormIdentifier($formIdentifier)
  {
      $this-&gt;formIdentifier = $formIdentifier;
  }

  public function getFormId()
  {
    $form_id = 'search_block_form';
    if($this-&gt;formIdentifier)
    {
        $form_id .= '-' . $this-&gt;formIdentifier;
    }
    return $form_id;
  }
}


Then you can call your form like this:

$form = \Drupal::service('class_resolver')-&gt;getInstanceFromDefinition('Drupal\mymodule\Form\Mymodule\SearchBlockForm');
$form-&gt;setFormIdentifier('some_custom_value');

return \Drupal::formBuilder()-&gt;getForm($form);


The key line of code here is this one:

$form-&gt;setFormIdentifier('some_custom_value');


If you pass a different value each time you generate the form, each form will get a different form ID. The form ID will be:

search_block_form-some_custom_value


Which will then be available in hook_form_alter with a $form_id of search_block_form-some_custom_value