How to add a field to menus? I am trying to add an extra text field to the menu entity. My field is showing up and saving input but the input saves for all menus not just the one I entered the data for.
This is how it is now:
function myModule_form_alter(&amp;$form, $form_state, $form_id) {
  if ($form_id == 'menu_edit_form') {
    $config = \Drupal::service('config.factory')-&gt;getEditable('myModule.settings');
    $my_field = $config-&gt;get('my_field');
    $form['my_field'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Title'),
    '#default_value' =&gt; $my_field,
    '#weight' =&gt; '0',
    '#required' =&gt; FALSE,
    );

    $form['actions']['submit']['#submit'][] = 'myModule_menu_edit_submit';
  }
}

function myModule_menu_edit_submit($form, $form_state) {
  $config = \Drupal::service('config.factory')-&gt;getEditable('myModule.settings');
  $config-&gt;set('my_field', $form_state-&gt;getValue('my_field'))-&gt;save();
}

I need to save different data for each form, so I was trying to do change the submit function to:
function myModule_menu_edit_submit($form, $form_state) {
  $key = $form_state-&gt;getformObject()-&gt;getEntity()-&gt;id();
  $config = \Drupal::service('config.factory')-&gt;getEditable('myModule.settings');
  $config-&gt;set($key, $form_state-&gt;getValue('my_field'))-&gt;save();
}

If I do this though, when I enter the data in the field and save, it says updated successfully but the field is blank. Not sure what I'm doing wrong.
I figured out how to add a field to the menus (not menu links, the actual menus). I use the machine name of the menu's title as a key and store the value with the key I use in the $form variable.
Here is my code:
function myModule_form_menu_edit_form_alter(&amp;$form, $form_state, $form_id) {
  $config = \Drupal::service('config.factory')-&gt;getEditable('myModule.settings');
  $my_field = $config-&gt;get(str_replace('-', '_', $form_state-&gt;getformObject()-&gt;getEntity()-&gt;id()));

  $form['my_field'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Title'),
  '#default_value' =&gt; $my_field,
  '#weight' =&gt; '0',
  '#required' =&gt; FALSE,
  );

  $form['actions']['submit']['#submit'][] = 'myModule_custom_submit';
}

function myModule_custom_submit($form, $form_state) {
  $key = str_replace('-', '_', $form_state-&gt;getformObject()-&gt;getEntity()-&gt;id());
  $config = \Drupal::service('config.factory')-&gt;getEditable('myModule.settings');
  $config-&gt;set($key, $form_state-&gt;getValue('my_field'))-&gt;save();
}