hook_form_alter

function hook_form_alter

hook_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)

Perform alterations before a form is rendered.

One popular use of this hook is to add form elements to the node form. When altering a node form, the node entity can be retrieved by invoking $form_state->getFormObject()->getEntity().

Implementations are responsible for adding cache contexts/tags/max-age as needed. See https://www.drupal.org/developing/api/8/cache.

In addition to hook_form_alter(), which is called for all forms, there are two more specific form hooks available. The first, 登录查看完整内容