将自定义提交处理程序添加到表单
如何添加自定义表单提交处理程序? 我尝试添加$form['#submit'][] = 'mymodule_form_submit';或$form['actions']['submit']['#submit'][] = 'mymodule_form_submit';到hook_form_alter()。 use Drupal\Core\Form\FormStateInterface; use Symfony\Component\HttpFoundation\Request; function MYMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($form_id == 'node_trends_form' || $form_id == 'node_trends_edit_form') { foreach (array_keys($form['actions']) as $action) { if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') { $form['actions']['submit']['#submit'][] = 'mymodule_form_submit'; } } } } function mymodule_form_submit(array …