Created
May 17, 2018 06:54
-
-
Save v1talii-dev/353e258e9dbc8814e9041b8aea02bfe8 to your computer and use it in GitHub Desktop.
D8: Add a custom submission handler to a form
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
<?php | |
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 $form, FormStateInterface $form_state){ | |
//die("why won't this execute? :("); | |
drupal_set_message("Why won't this message show?"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment