I'm trying to attach a submit handler to an entity form (language_delete_form) provided by the ConfigurableLanguage config entity. On the form alter function for that form, the top-level submit handler value looks like $form['#submit'] = ['::submitForm'].

I want to add an additional submission handler, so it looks like $form['#submit'] = ['::submitForm', 'locale_delete_language_submit']. However, locale_delete_language_submit is not being called during the submission process (I would expect it to be invoked after LanguageDeleteForm::submitForm is invoked). What am I missing here?

Based on Berdir's comment here (https://www.drupal.org/project/drupal/issues/2252165#comment-9437863) I would have expected the function to be invoked.

Here's my code:

 * Implements hook_form_FORM_ID_alter() for language_delete_form().
function locale_form_language_delete_form_alter(&$form, FormStateInterface $form_state) {
  $x = 5;
  $form['#submit'][] = 'locale_delete_language_submit';

 * @param $form
 * @param \Drupal\Core\Form\FormStateInterface $form_state
function locale_delete_language_submit($form, FormStateInterface $form_state) {
  $defined_value = 'fifty';

As discussed in slack, you misunderstood my comment. You should add it to the form-level submit callbacks if and only if that form has no button-level submit callbacks.

If it has, then you need to add yours there as well.

  • Yep, I had posted this in a couple of places, covering my bases... thanks for the assistance. Aug 27 '18 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.