Chris@0: [], Chris@0: ]; Chris@0: $link_text = $link['title']; Chris@0: Chris@0: if (!empty($variables['element']['#active'])) { Chris@0: $variables['is_active'] = TRUE; Chris@0: Chris@0: // Add text to indicate active tab for non-visual users. Chris@17: $active = new FormattableMarkup('@label', ['@label' => t('(active tab)')]); Chris@0: $link_text = t('@local-task-title@active', ['@local-task-title' => $link_text, '@active' => $active]); Chris@0: } Chris@0: Chris@0: $link['localized_options']['set_active_class'] = TRUE; Chris@0: Chris@0: $variables['link'] = [ Chris@0: '#type' => 'link', Chris@0: '#title' => $link_text, Chris@0: '#url' => $link['url'], Chris@0: '#options' => $link['localized_options'], Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prepares variables for single local action link templates. Chris@0: * Chris@0: * Default template: menu-local-action.html.twig. Chris@0: * Chris@0: * @param array $variables Chris@0: * An associative array containing: Chris@0: * - element: A render element containing: Chris@0: * - #link: A menu link array with 'title', 'url', and (optionally) Chris@0: * 'localized_options' keys. Chris@0: */ Chris@0: function template_preprocess_menu_local_action(&$variables) { Chris@0: $link = $variables['element']['#link']; Chris@0: $link += [ Chris@0: 'localized_options' => [], Chris@0: ]; Chris@0: $link['localized_options']['attributes']['class'][] = 'button'; Chris@0: $link['localized_options']['attributes']['class'][] = 'button-action'; Chris@0: $link['localized_options']['set_active_class'] = TRUE; Chris@0: Chris@0: $variables['link'] = [ Chris@0: '#type' => 'link', Chris@0: '#title' => $link['title'], Chris@0: '#options' => $link['localized_options'], Chris@0: '#url' => $link['url'], Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns an array containing the names of system-defined (default) menus. Chris@0: */ Chris@0: function menu_list_system_menus() { Chris@0: return [ Chris@0: 'tools' => 'Tools', Chris@0: 'admin' => 'Administration', Chris@0: 'account' => 'User account menu', Chris@0: 'main' => 'Main navigation', Chris@0: 'footer' => 'Footer menu', Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Collects the local tasks (tabs) for the current route. Chris@0: * Chris@0: * @param int $level Chris@0: * The level of tasks you ask for. Primary tasks are 0, secondary are 1. Chris@0: * Chris@0: * @return array Chris@0: * An array containing Chris@0: * - tabs: Local tasks for the requested level. Chris@0: * - route_name: The route name for the current page used to collect the local Chris@0: * tasks. Chris@0: * Chris@0: * @see hook_menu_local_tasks_alter() Chris@0: * @see https://www.drupal.org/node/2544940 Chris@0: * Chris@0: * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. Chris@0: */ Chris@0: function menu_local_tasks($level = 0) { Chris@0: /** @var \Drupal\Core\Menu\LocalTaskManagerInterface $manager */ Chris@0: $manager = \Drupal::service('plugin.manager.menu.local_task'); Chris@0: return $manager->getLocalTasks(\Drupal::routeMatch()->getRouteName(), $level); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the rendered local tasks at the top level. Chris@0: * Chris@0: * @see https://www.drupal.org/node/2874695 Chris@0: * Chris@0: * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. Chris@0: */ Chris@0: function menu_primary_local_tasks() { Chris@0: /** @var \Drupal\Core\Menu\LocalTaskManagerInterface $manager */ Chris@0: $manager = \Drupal::service('plugin.manager.menu.local_task'); Chris@0: $links = $manager->getLocalTasks(\Drupal::routeMatch()->getRouteName(), 0); Chris@0: // Do not display single tabs. Chris@0: return count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : ''; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the rendered local tasks at the second level. Chris@0: * Chris@0: * @see https://www.drupal.org/node/2874695 Chris@0: * Chris@0: * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. Chris@0: */ Chris@0: function menu_secondary_local_tasks() { Chris@0: /** @var \Drupal\Core\Menu\LocalTaskManagerInterface $manager */ Chris@0: $manager = \Drupal::service('plugin.manager.menu.local_task'); Chris@0: $links = $manager->getLocalTasks(\Drupal::routeMatch()->getRouteName(), 1); Chris@0: // Do not display single tabs. Chris@0: return count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : ''; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a renderable element for the primary and secondary tabs. Chris@0: */ Chris@0: function menu_local_tabs() { Chris@0: $build = [ Chris@0: '#theme' => 'menu_local_tasks', Chris@0: '#primary' => menu_primary_local_tasks(), Chris@0: '#secondary' => menu_secondary_local_tasks(), Chris@0: ]; Chris@0: return !empty($build['#primary']) || !empty($build['#secondary']) ? $build : []; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Clears all cached menu data. Chris@0: * Chris@0: * This should be called any time broad changes Chris@0: * might have been made to the router items or menu links. Chris@17: * Chris@17: * @deprecated in Drupal 8.6.0, will be removed before Drupal 9.0.0. Use Chris@17: * \Drupal::cache('menu')->invalidateAll() instead. Chris@17: * Chris@17: * @see https://www.drupal.org/node/2989138 Chris@0: */ Chris@0: function menu_cache_clear_all() { Chris@17: @trigger_error("menu_cache_clear_all() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use \Drupal::cache('menu')->invalidateAll() instead. See https://www.drupal.org/node/2989138", E_USER_DEPRECATED); Chris@0: \Drupal::cache('menu')->invalidateAll(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @} End of "addtogroup menu". Chris@0: */