Submit handler does not work I am trying to handle multiple submit buttons, but the handlers does not get called.

I am following http://www.hooksupport.com/blog/drupal-8-how-handle-multiple-submission-buttons-drupal-8-form, and this is the code I am using.

$form['add_field'] = array
    (
      '#type' =&gt; 'submit',
      '#value' =&gt; $this-&gt;t('Create field'),
      '#submit' =&gt; array('::create_field_submit'),
    );

 public function create_field_submit(array &amp;$form, FormStateInterface $form_state){
     drupal_set_message(t('Form Submitted Successfully'), 'status', TRUE);
}


The message I've trying to send does not appear. Why?
If this is not working, then the reason for this is, that the block plugin is not the form class. This is BlockForm, which calls the methods in the plugin while building, validating and submitting the form. So if you want to add custom code to the submit in a block plugin override:

public function blockSubmit($form, FormStateInterface $form_state) {}


This code will then be included when the form class calls submitConfigurationForm().

If you have more than one submit button you can check the triggering element in $form_state.



Edit:

Another option is to use a static submit function instead of the class method.