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-03-09 15:57:27 +00:00
|
|
|
use Drupal\Component\Utility\SafeMarkup;
|
2015-01-22 19:24:44 +00:00
|
|
|
use Drupal\Core\Render\Element;
|
|
|
|
|
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'])) {
|
2015-04-18 15:48:42 +00:00
|
|
|
$variables['is_active'] = TRUE;
|
2009-11-08 12:30:35 +00:00
|
|
|
|
2015-03-09 15:57:27 +00:00
|
|
|
// Add text to indicate active tab for non-visual users.
|
2015-03-29 22:13:25 +00:00
|
|
|
$active = SafeMarkup::format('<span class="visually-hidden">@label</span>', array('@label' => t('(active tab)')));
|
2015-03-09 15:57:27 +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
|
|
|
}
|
2015-03-09 15:57:27 +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
|
|
|
/**
|
Issue #507488 by lauriii, mdrummond, Wim Leers, Manuel Garcia, pwolanin, davidhernandez, chx, jibran, andypost, dawehner, Xano, tuutti, Gábor Hojtsy, LewisNyman, maximiliam, eiriksm, borisson_, bill richardson, Fabianx, joelpittet, Jeff Burnz, xjm, webchick, Bojhan, EclipseGc, emma.maria, tim.plunkett: Convert page elements (local tasks, actions) into blocks
2015-09-01 11:24:09 +00:00
|
|
|
* Collects the local tasks (tabs) for the current route.
|
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.
|
Issue #507488 by lauriii, mdrummond, Wim Leers, Manuel Garcia, pwolanin, davidhernandez, chx, jibran, andypost, dawehner, Xano, tuutti, Gábor Hojtsy, LewisNyman, maximiliam, eiriksm, borisson_, bill richardson, Fabianx, joelpittet, Jeff Burnz, xjm, webchick, Bojhan, EclipseGc, emma.maria, tim.plunkett: Convert page elements (local tasks, actions) into blocks
2015-09-01 11:24:09 +00:00
|
|
|
* - route_name: The route name for the current page used to collect the local
|
|
|
|
* tasks.
|
2013-02-18 17:03:05 +00:00
|
|
|
*
|
|
|
|
* @see hook_menu_local_tasks_alter()
|
Issue #507488 by lauriii, mdrummond, Wim Leers, Manuel Garcia, pwolanin, davidhernandez, chx, jibran, andypost, dawehner, Xano, tuutti, Gábor Hojtsy, LewisNyman, maximiliam, eiriksm, borisson_, bill richardson, Fabianx, joelpittet, Jeff Burnz, xjm, webchick, Bojhan, EclipseGc, emma.maria, tim.plunkett: Convert page elements (local tasks, actions) into blocks
2015-09-01 11:24:09 +00:00
|
|
|
*
|
|
|
|
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
|
2009-08-22 19:58:28 +00:00
|
|
|
*/
|
|
|
|
function menu_local_tasks($level = 0) {
|
Issue #507488 by lauriii, mdrummond, Wim Leers, Manuel Garcia, pwolanin, davidhernandez, chx, jibran, andypost, dawehner, Xano, tuutti, Gábor Hojtsy, LewisNyman, maximiliam, eiriksm, borisson_, bill richardson, Fabianx, joelpittet, Jeff Burnz, xjm, webchick, Bojhan, EclipseGc, emma.maria, tim.plunkett: Convert page elements (local tasks, actions) into blocks
2015-09-01 11:24:09 +00:00
|
|
|
/** @var \Drupal\Core\Menu\LocalTaskManagerInterface $manager */
|
|
|
|
$manager = \Drupal::service('plugin.manager.menu.local_task');
|
|
|
|
return $manager->getLocalTasks(\Drupal::routeMatch()->getRouteName(), $level);
|
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.
|
Issue #507488 by lauriii, mdrummond, Wim Leers, Manuel Garcia, pwolanin, davidhernandez, chx, jibran, andypost, dawehner, Xano, tuutti, Gábor Hojtsy, LewisNyman, maximiliam, eiriksm, borisson_, bill richardson, Fabianx, joelpittet, Jeff Burnz, xjm, webchick, Bojhan, EclipseGc, emma.maria, tim.plunkett: Convert page elements (local tasks, actions) into blocks
2015-09-01 11:24:09 +00:00
|
|
|
*
|
|
|
|
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
|
2007-07-04 15:49:44 +00:00
|
|
|
*/
|
2007-02-11 09:30:51 +00:00
|
|
|
function menu_primary_local_tasks() {
|
Issue #507488 by lauriii, mdrummond, Wim Leers, Manuel Garcia, pwolanin, davidhernandez, chx, jibran, andypost, dawehner, Xano, tuutti, Gábor Hojtsy, LewisNyman, maximiliam, eiriksm, borisson_, bill richardson, Fabianx, joelpittet, Jeff Burnz, xjm, webchick, Bojhan, EclipseGc, emma.maria, tim.plunkett: Convert page elements (local tasks, actions) into blocks
2015-09-01 11:24:09 +00:00
|
|
|
/** @var \Drupal\Core\Menu\LocalTaskManagerInterface $manager */
|
|
|
|
$manager = \Drupal::service('plugin.manager.menu.local_task');
|
|
|
|
$links = $manager->getLocalTasks(\Drupal::routeMatch()->getRouteName(), 0);
|
2009-08-22 19:58:28 +00:00
|
|
|
// 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.
|
Issue #507488 by lauriii, mdrummond, Wim Leers, Manuel Garcia, pwolanin, davidhernandez, chx, jibran, andypost, dawehner, Xano, tuutti, Gábor Hojtsy, LewisNyman, maximiliam, eiriksm, borisson_, bill richardson, Fabianx, joelpittet, Jeff Burnz, xjm, webchick, Bojhan, EclipseGc, emma.maria, tim.plunkett: Convert page elements (local tasks, actions) into blocks
2015-09-01 11:24:09 +00:00
|
|
|
*
|
|
|
|
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
|
2007-07-04 15:49:44 +00:00
|
|
|
*/
|
2007-01-24 14:48:36 +00:00
|
|
|
function menu_secondary_local_tasks() {
|
Issue #507488 by lauriii, mdrummond, Wim Leers, Manuel Garcia, pwolanin, davidhernandez, chx, jibran, andypost, dawehner, Xano, tuutti, Gábor Hojtsy, LewisNyman, maximiliam, eiriksm, borisson_, bill richardson, Fabianx, joelpittet, Jeff Burnz, xjm, webchick, Bojhan, EclipseGc, emma.maria, tim.plunkett: Convert page elements (local tasks, actions) into blocks
2015-09-01 11:24:09 +00:00
|
|
|
/** @var \Drupal\Core\Menu\LocalTaskManagerInterface $manager */
|
|
|
|
$manager = \Drupal::service('plugin.manager.menu.local_task');
|
|
|
|
$links = $manager->getLocalTasks(\Drupal::routeMatch()->getRouteName(), 1);
|
2009-08-22 19:58:28 +00:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|