Skip to content

Instantly share code, notes, and snippets.

@tarnus
Created December 19, 2015 17:05
Show Gist options
  • Save tarnus/dfb11b78fc64a1fddf25 to your computer and use it in GitHub Desktop.
Save tarnus/dfb11b78fc64a1fddf25 to your computer and use it in GitHub Desktop.
drupal 8 form alter submit handler
function mymodule_form_node_form_alter(&$form, FormStateInterface $form_state) {
// For entity builders.
kint($form['#form_id']);
if($form['#form_id'] == 'node_page_edit_form') {
foreach (array_keys($form['actions']) as $action) {
if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
$form['actions'][$action]['#submit'][] = 'mymodule_node_form_submit';
}
}
}
}
function mymodule_node_form_submit($form, FormStateInterface $form_state) {
$node = $form_state->getFormObject()->getEntity();
\Drupal::logger('mfdev')->notice('Got here ') ;
drupal_set_message("I was here");
// mymodule_do_something($node);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment