You are here

function menu_badges_menu_edit_item_submit in Menu Badges 8

Same name and namespace in other branches
  1. 7 menu_badges.module \menu_badges_menu_edit_item_submit()

Submit handler for saving menu badge options.

1 string reference to 'menu_badges_menu_edit_item_submit'
menu_badges_form_alter in ./menu_badges.module
Implements hook_form_alter().

File

./menu_badges.module, line 79
Menu Badges module file.

Code

function menu_badges_menu_edit_item_submit(&$form, &$form_state) {
  $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
  $menu_badge_id = $form_state
    ->getValue('menu_badges_id');
  if (empty($menu_badge_id)) {
    $menu_link_manager
      ->updateDefinition($form_state
      ->getValue('menu_link_id'), [
      'options' => [],
    ]);
  }
  else {
    $menu_link_manager
      ->updateDefinition($form_state
      ->getValue('menu_link_id'), [
      'options' => [
        'link_badge' => [
          'id' => $menu_badge_id,
        ],
      ],
    ]);
  }
}