2002-12-24 15:40:32 +00:00
|
|
|
<?php
|
2003-12-27 21:29:20 +00:00
|
|
|
|
2004-07-22 16:06:54 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* API for the Drupal menu system.
|
|
|
|
*/
|
|
|
|
|
2003-12-17 22:15:35 +00:00
|
|
|
/**
|
2015-01-22 19:24:44 +00:00
|
|
|
* @addtogroup menu
|
2003-12-17 22:15:35 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2015-01-22 19:24:44 +00:00
|
|
|
use Drupal\Component\Utility\String;
|
|
|
|
use Drupal\Core\Render\Element;
|
|
|
|
use Drupal\Core\Template\Attribute;
|
|
|
|
|
2011-12-06 12:18:12 +00:00
|
|
|
|
2007-07-04 15:49:44 +00:00
|
|
|
/**
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
* Prepares variables for single local task link templates.
|
2007-12-06 09:58:34 +00:00
|
|
|
*
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
* Default template: menu-local-task.html.twig.
|
|
|
|
*
|
|
|
|
* @param array $variables
|
2009-10-09 01:00:08 +00:00
|
|
|
* An associative array containing:
|
2010-04-13 15:23:03 +00:00
|
|
|
* - element: A render element containing:
|
2015-02-03 09:59:20 +00:00
|
|
|
* - #link: A menu link array with 'title', 'url', and (optionally)
|
|
|
|
* 'localized_options' keys.
|
2010-04-13 15:23:03 +00:00
|
|
|
* - #active: A boolean indicating whether the local task is active.
|
2007-07-04 15:49:44 +00:00
|
|
|
*/
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
function template_preprocess_menu_local_task(&$variables) {
|
2009-10-11 06:05:53 +00:00
|
|
|
$link = $variables['element']['#link'];
|
2013-02-18 17:03:05 +00:00
|
|
|
$link += array(
|
|
|
|
'localized_options' => array(),
|
|
|
|
);
|
2014-12-13 20:44:18 +00:00
|
|
|
$link_text = $link['title'];
|
2009-11-08 12:30:35 +00:00
|
|
|
|
|
|
|
if (!empty($variables['element']['#active'])) {
|
|
|
|
// Add text to indicate active tab for non-visual users.
|
2014-12-13 20:44:18 +00:00
|
|
|
$active = '<span class="visually-hidden">' . t('(active tab)') . '</span>';
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
$variables['attributes']['class'] = array('active');
|
2009-11-08 12:30:35 +00:00
|
|
|
|
2014-12-13 20:44:18 +00:00
|
|
|
// If the link does not contain HTML already, String::checkPlain() it now.
|
|
|
|
// After we set 'html'=TRUE the link will not be sanitized by l().
|
|
|
|
if (empty($link['localized_options']['html'])) {
|
2015-02-03 09:59:20 +00:00
|
|
|
$link_text = String::checkPlain($link_text);
|
2014-12-13 20:44:18 +00:00
|
|
|
}
|
|
|
|
$link['localized_options']['html'] = TRUE;
|
2015-02-03 09:59:20 +00:00
|
|
|
$link_text = t('!local-task-title!active', array('!local-task-title' => $link_text, '!active' => $active));
|
2009-11-08 12:30:35 +00:00
|
|
|
}
|
2014-01-23 18:04:41 +00:00
|
|
|
$link['localized_options']['set_active_class'] = TRUE;
|
|
|
|
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
$variables['link'] = array(
|
|
|
|
'#type' => 'link',
|
2014-12-13 20:44:18 +00:00
|
|
|
'#title' => $link_text,
|
2014-10-09 06:39:37 +00:00
|
|
|
'#url' => $link['url'],
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
'#options' => $link['localized_options'],
|
|
|
|
);
|
2003-09-28 10:51:40 +00:00
|
|
|
}
|
2002-12-24 15:40:32 +00:00
|
|
|
|
2009-08-22 19:58:28 +00:00
|
|
|
/**
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
* Prepares variables for single local action link templates.
|
2009-08-22 19:58:28 +00:00
|
|
|
*
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
* Default template: menu-local-action.html.twig.
|
|
|
|
*
|
|
|
|
* @param array $variables
|
2009-10-09 01:00:08 +00:00
|
|
|
* An associative array containing:
|
2010-04-13 15:23:03 +00:00
|
|
|
* - element: A render element containing:
|
2015-02-03 09:59:20 +00:00
|
|
|
* - #link: A menu link array with 'title', 'url', and (optionally)
|
|
|
|
* 'localized_options' keys.
|
2009-08-22 19:58:28 +00:00
|
|
|
*/
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
function template_preprocess_menu_local_action(&$variables) {
|
2009-10-11 06:05:53 +00:00
|
|
|
$link = $variables['element']['#link'];
|
2012-11-19 11:43:55 +00:00
|
|
|
$link += array(
|
|
|
|
'localized_options' => array(),
|
|
|
|
);
|
|
|
|
$link['localized_options']['attributes']['class'][] = 'button';
|
2013-01-02 12:00:25 +00:00
|
|
|
$link['localized_options']['attributes']['class'][] = 'button-action';
|
2014-01-23 18:04:41 +00:00
|
|
|
$link['localized_options']['set_active_class'] = TRUE;
|
2009-12-03 20:21:50 +00:00
|
|
|
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
$variables['link'] = array(
|
|
|
|
'#type' => 'link',
|
|
|
|
'#title' => $link['title'],
|
|
|
|
'#options' => $link['localized_options'],
|
2014-10-09 06:39:37 +00:00
|
|
|
'#url' => $link['url'],
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
);
|
2009-08-22 19:58:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 14:44:03 +00:00
|
|
|
/**
|
2012-08-31 15:56:36 +00:00
|
|
|
* Returns an array containing the names of system-defined (default) menus.
|
2007-07-25 14:44:03 +00:00
|
|
|
*/
|
|
|
|
function menu_list_system_menus() {
|
2009-10-09 08:02:25 +00:00
|
|
|
return array(
|
2012-10-25 15:53:18 +00:00
|
|
|
'tools' => 'Tools',
|
|
|
|
'admin' => 'Administration',
|
|
|
|
'account' => 'User account menu',
|
|
|
|
'main' => 'Main navigation',
|
2012-11-20 11:36:51 +00:00
|
|
|
'footer' => 'Footer menu',
|
2009-10-09 08:02:25 +00:00
|
|
|
);
|
2007-07-25 14:44:03 +00:00
|
|
|
}
|
|
|
|
|
2007-02-11 09:30:51 +00:00
|
|
|
/**
|
2009-08-22 19:58:28 +00:00
|
|
|
* Collects the local tasks (tabs), action links, and the root path.
|
2007-02-11 09:30:51 +00:00
|
|
|
*
|
2013-10-04 04:27:56 +00:00
|
|
|
* @param int $level
|
2007-05-16 13:45:17 +00:00
|
|
|
* The level of tasks you ask for. Primary tasks are 0, secondary are 1.
|
2010-03-26 17:14:46 +00:00
|
|
|
*
|
2013-10-04 04:27:56 +00:00
|
|
|
* @return array
|
2009-08-22 19:58:28 +00:00
|
|
|
* An array containing
|
2013-02-18 17:03:05 +00:00
|
|
|
* - tabs: Local tasks for the requested level.
|
|
|
|
* - actions: Action links for the requested level.
|
2009-08-22 19:58:28 +00:00
|
|
|
* - root_path: The router path for the current page. If the current page is
|
|
|
|
* a default local task, then this corresponds to the parent tab.
|
2013-02-18 17:03:05 +00:00
|
|
|
*
|
|
|
|
* @see hook_menu_local_tasks()
|
|
|
|
* @see hook_menu_local_tasks_alter()
|
2009-08-22 19:58:28 +00:00
|
|
|
*/
|
|
|
|
function menu_local_tasks($level = 0) {
|
|
|
|
$data = &drupal_static(__FUNCTION__);
|
|
|
|
$root_path = &drupal_static(__FUNCTION__ . ':root_path', '');
|
|
|
|
$empty = array(
|
2013-02-18 17:03:05 +00:00
|
|
|
'tabs' => array(),
|
|
|
|
'actions' => array(),
|
2009-08-22 19:58:28 +00:00
|
|
|
'root_path' => &$root_path,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!isset($data)) {
|
2013-09-20 09:53:46 +00:00
|
|
|
// Look for route-based tabs.
|
|
|
|
$data['tabs'] = array();
|
|
|
|
$data['actions'] = array();
|
|
|
|
|
2014-06-24 12:39:26 +00:00
|
|
|
$route_name = \Drupal::routeMatch()->getRouteName();
|
2014-09-15 09:22:01 +00:00
|
|
|
if (!\Drupal::request()->attributes->has('exception') && !empty($route_name)) {
|
2013-09-21 15:23:51 +00:00
|
|
|
$manager = \Drupal::service('plugin.manager.menu.local_task');
|
2013-09-20 09:53:46 +00:00
|
|
|
$local_tasks = $manager->getTasksBuild($route_name);
|
|
|
|
foreach ($local_tasks as $level => $items) {
|
|
|
|
$data['tabs'][$level] = empty($data['tabs'][$level]) ? $items : array_merge($data['tabs'][$level], $items);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-18 17:03:05 +00:00
|
|
|
// Allow modules to dynamically add further tasks.
|
2013-09-16 03:58:06 +00:00
|
|
|
$module_handler = \Drupal::moduleHandler();
|
2013-02-18 17:03:05 +00:00
|
|
|
foreach ($module_handler->getImplementations('menu_local_tasks') as $module) {
|
|
|
|
$function = $module . '_menu_local_tasks';
|
2013-10-04 04:27:56 +00:00
|
|
|
$function($data, $route_name);
|
2013-02-18 17:03:05 +00:00
|
|
|
}
|
|
|
|
// Allow modules to alter local tasks.
|
2013-10-04 04:27:56 +00:00
|
|
|
$module_handler->alter('menu_local_tasks', $data, $route_name);
|
2007-01-31 21:26:56 +00:00
|
|
|
}
|
2007-06-30 19:46:58 +00:00
|
|
|
|
2009-08-22 19:58:28 +00:00
|
|
|
if (isset($data['tabs'][$level])) {
|
|
|
|
return array(
|
|
|
|
'tabs' => $data['tabs'][$level],
|
|
|
|
'actions' => $data['actions'],
|
|
|
|
'root_path' => $root_path,
|
|
|
|
);
|
2007-06-30 19:46:58 +00:00
|
|
|
}
|
2013-02-18 17:03:05 +00:00
|
|
|
elseif (!empty($data['actions'])) {
|
2009-12-03 20:21:50 +00:00
|
|
|
return array('actions' => $data['actions']) + $empty;
|
|
|
|
}
|
2009-08-22 19:58:28 +00:00
|
|
|
return $empty;
|
2007-02-11 09:30:51 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:44 +00:00
|
|
|
/**
|
|
|
|
* Returns the rendered local tasks at the top level.
|
|
|
|
*/
|
2007-02-11 09:30:51 +00:00
|
|
|
function menu_primary_local_tasks() {
|
2009-08-22 19:58:28 +00:00
|
|
|
$links = menu_local_tasks(0);
|
|
|
|
// Do not display single tabs.
|
2014-03-31 17:37:55 +00:00
|
|
|
return count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : '';
|
2004-04-15 20:49:42 +00:00
|
|
|
}
|
2003-09-28 10:51:40 +00:00
|
|
|
|
2007-07-04 15:49:44 +00:00
|
|
|
/**
|
|
|
|
* Returns the rendered local tasks at the second level.
|
|
|
|
*/
|
2007-01-24 14:48:36 +00:00
|
|
|
function menu_secondary_local_tasks() {
|
2009-08-22 19:58:28 +00:00
|
|
|
$links = menu_local_tasks(1);
|
|
|
|
// Do not display single tabs.
|
2014-03-31 17:37:55 +00:00
|
|
|
return count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : '';
|
2009-08-22 19:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the rendered local actions at the current level.
|
|
|
|
*/
|
2013-05-28 01:20:55 +00:00
|
|
|
function menu_get_local_actions() {
|
2009-08-22 19:58:28 +00:00
|
|
|
$links = menu_local_tasks();
|
2014-06-24 12:39:26 +00:00
|
|
|
$route_name = Drupal::routeMatch()->getRouteName();
|
2013-09-16 03:58:06 +00:00
|
|
|
$manager = \Drupal::service('plugin.manager.menu.local_action');
|
2013-10-13 12:40:37 +00:00
|
|
|
return $manager->getActionsForRoute($route_name) + $links['actions'];
|
2004-09-16 07:17:56 +00:00
|
|
|
}
|
|
|
|
|
2007-05-27 20:31:13 +00:00
|
|
|
/**
|
2012-08-31 15:56:36 +00:00
|
|
|
* Returns the router path, or the path for a default local task's parent.
|
2007-06-30 19:46:58 +00:00
|
|
|
*/
|
|
|
|
function menu_tab_root_path() {
|
2009-08-22 19:58:28 +00:00
|
|
|
$links = menu_local_tasks();
|
|
|
|
return $links['root_path'];
|
2007-06-30 19:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-20 04:03:51 +00:00
|
|
|
* Returns a renderable element for the primary and secondary tabs.
|
|
|
|
*/
|
|
|
|
function menu_local_tabs() {
|
2013-02-18 17:03:05 +00:00
|
|
|
$build = array(
|
2010-11-20 04:03:51 +00:00
|
|
|
'#theme' => 'menu_local_tasks',
|
|
|
|
'#primary' => menu_primary_local_tasks(),
|
|
|
|
'#secondary' => menu_secondary_local_tasks(),
|
|
|
|
);
|
2013-02-18 17:03:05 +00:00
|
|
|
return !empty($build['#primary']) || !empty($build['#secondary']) ? $build : array();
|
2010-11-20 04:03:51 +00:00
|
|
|
}
|
|
|
|
|
2007-05-16 13:45:17 +00:00
|
|
|
/**
|
2012-08-31 15:56:36 +00:00
|
|
|
* Clears all cached menu data.
|
|
|
|
*
|
|
|
|
* This should be called any time broad changes
|
2007-07-04 15:49:44 +00:00
|
|
|
* might have been made to the router items or menu links.
|
2007-05-16 13:45:17 +00:00
|
|
|
*/
|
|
|
|
function menu_cache_clear_all() {
|
2014-07-30 12:04:04 +00:00
|
|
|
\Drupal::cache('menu')->invalidateAll();
|
2007-05-16 13:45:17 +00:00
|
|
|
}
|
|
|
|
|
2008-01-28 16:05:17 +00:00
|
|
|
/**
|
2015-01-22 19:24:44 +00:00
|
|
|
* @} End of "addtogroup menu".
|
2008-01-28 16:05:17 +00:00
|
|
|
*/
|