Created
December 19, 2015 17:05
-
-
Save tarnus/dfb11b78fc64a1fddf25 to your computer and use it in GitHub Desktop.
drupal 8 form alter submit handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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