You are here

function menu_link_weight_form_menu_link_content_form_alter in Menu Link Weight 8

Same name and namespace in other branches
  1. 8.2 menu_link_weight.menu_ui.inc \menu_link_weight_form_menu_link_content_form_alter()

Implements hook_form_BASE_FORM_ID_alter() for menu_link_content edit forms.

File

./menu_link_weight.menu_ui.inc, line 28

Code

function menu_link_weight_form_menu_link_content_form_alter(&$form, FormStateInterface $form_state) {
  _menu_link_weight_menu_link_form_alter($form, $form_state);

  /** @var \Drupal\menu_link_content\MenuLinkContentInterface $link */
  $link = $form_state
    ->getBuildInfo()['callback_object']
    ->getEntity();

  // Get the ID for the current menu link.
  $form_state
    ->set([
    'menu_link_weight',
    'current_mlid',
  ], $link
    ->getPluginId());

  // Get the title for the current menu link.
  $form_state
    ->set([
    'menu_link_weight',
    'new_item_title',
  ], $link
    ->getTitle());

  /** @see menu_ui_form_node_form_alter() */
  foreach (array_keys($form['actions']) as $action) {
    if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
      $form['actions'][$action]['#submit'][] = 'menu_link_weight_menu_link_content_form_submit';
    }
  }
}