How to get value properly from form field? I search the best way to get value from  form field, and I would like to know if my code section below it's the only way to get value from field ($value = $var[0]['value']) or if it's possible to write this better:

/**
 * Implements hook_form_alter().
 */
function my_module_form_alter(&amp;$form, FormStateInterface $form_state, $form_id){
  if ($form_id == 'node_bibliographie_form') {

    $form['#validate'][] = 'node_bibliographie_form_validate';

    foreach (array_keys($form['actions']) as $action) {
      if ($action != 'preview' &amp;&amp; isset($form['actions'][$action]['#type']) &amp;&amp; $form['actions'][$action]['#type'] === 'submit') {
       $form['actions'][$action]['#submit'][] = 'my_module_bibliographie_form_submit';
      }
    }
  }
}

function my_module_bibliographie_form_submit(&amp;$form, FormStateInterface $form_state){
  // Get the submitted entity.
  $key        = $form_state-&gt;getValue('field_key');
  $id_dossier = $form_state-&gt;getValue('field_dossier_reference');

  if (isset($id_dossier) &amp;&amp; isset($key) &amp;&amp;  !empty($key) &amp;&amp; !empty($id_dossier)) {
    kint($id_dossier[0]['target_id']);
    //ugly ?
    $collection_key = $key[0]['value'];
   }
}
If  you need to get the value of the array you can use below method.

 $values = $form_state-&gt;getValue(array('name_of the array', 'key'));