You are here

function menu_badges_menu_local_actions_alter in Menu Badges 8

Implements hook_menu_local_actions_alter().

File

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

Code

function menu_badges_menu_local_actions_alter(&$local_actions) {
  $menu_badge_manager = \Drupal::service('menu_badges.manager');
  $local_badges = $menu_badge_manager
    ->getLocalBadges();
  if (!empty($local_badges[\Drupal\menu_badges\MenuBadgesManager::LOCAL_ACTION])) {
    foreach ($local_badges[\Drupal\menu_badges\MenuBadgesManager::LOCAL_ACTION] as $route_id => $badge) {
      $route_id = str_replace('|', '.', $route_id);
      if (!empty($local_actions[$route_id])) {
        $local_actions[$route_id]['options']['link_badge'] = $badge;
      }
      else {
        unset($local_actions[$route_id]['options']['link_badge']);
      }
    }
  }
}