Form submit : how to pass parameters? I have a form with a submit button :

$form['my-custom-submit'.$i] = array(
    '#name' =&gt; $nid,
    '#type' =&gt; 'submit',
    '#value' =&gt; 'Delete Node',
    '#submit' =&gt; array('::deleteNode'),
);


This submit button calls this function :

public function deleteNode(array &amp;$form, FormStateInterface $form_state, $nid)
{
    // My Delete function($nid)
    drupal_set_message('Delete : '.$nid, 'status');
    $form_state-&gt;setRedirect('my-route');
}


How can I pass the $nid parameter to my deleteNode function ?
Or if there is a way to get the '#name' in my function, it could be perfect too.
I cannot pass it through a $form_state->getValue('abc') because it is a list of incremented ids : $form['my-custom-submit'.$i].

I have searched google for 4 hours without finding, but I'm pretty sure that there is a simple way to accomplish this (newbie).

Thanks in advance.

Edit :
I found that the '#name' and value of the submit are passed to my function, I can get it like this :

public function deleteNode(array &amp;$form, FormStateInterface $form_state)
{
    $last_nid = '';

    foreach ($form_state-&gt;getValues() as $key =&gt; $value) {
      $last_nid = $key;
    }
    // My Delete function($last_nid)
    drupal_set_message('Delete : '.$last_nid, 'status');
    $form_state-&gt;setRedirect('my-route');
}


Which isn't really elegant but does the job.
Is there a better way to get it ?
You can try this. Set the node id in the form element

    '#nid' =&gt; $nid,


and use FormState::getTriggeringElement to get the triggering element and the property #nid:

  public function deleteNode(array &amp;$form, FormStateInterface $form_state) {

    $trigger = $form_state-&gt;getTriggeringElement();
    $nid = $trigger['#nid'];


In some cases you have to get the triggering button from the parent property:

    $clicked_button = end($form_state-&gt;getTriggeringElement()['#parents']);