diff --git a/core/includes/menu.inc b/core/includes/menu.inc
index 5457ff8..472f51e 100644
--- a/core/includes/menu.inc
+++ b/core/includes/menu.inc
@@ -8,7 +8,6 @@
use Drupal\Component\Utility\String;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Render\Element;
-use Drupal\Core\Template\Attribute;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
/**
@@ -221,60 +220,53 @@ function _menu_link_translate(&$item) {
}
/**
- * Implements template_preprocess_HOOK() for theme_menu_tree().
+ * Prepares variables for menu tree templates.
+ *
+ * Default template: menu-tree.html.twig.
+ *
+ * @param array $variables
+ * An associative array containing:
+ * - tree: A render array for a menu tree.
*/
function template_preprocess_menu_tree(&$variables) {
$variables['tree'] = $variables['tree']['#children'];
}
/**
- * Returns HTML for a wrapper for a menu sub-tree.
- *
- * @param $variables
- * An associative array containing:
- * - tree: An HTML string containing the tree's items.
+ * Prepares variables for menu link plus submenu templates.
*
- * @see template_preprocess_menu_tree()
- * @ingroup themeable
- */
-function theme_menu_tree($variables) {
- return '
' . $variables['tree'] . '
';
-}
-
-/**
- * Returns HTML for a menu link and submenu.
+ * Default template: menu-link.html.twig.
*
- * @param $variables
+ * @param array $variables
* An associative array containing:
* - element: Structured array data for a menu link.
- *
- * @ingroup themeable
*/
-function theme_menu_link(array $variables) {
+function template_preprocess_menu_link(&$variables) {
$element = $variables['element'];
- $sub_menu = '';
-
- if ($element['#below']) {
- $sub_menu = drupal_render($element['#below']);
- }
$element['#localized_options']['set_active_class'] = TRUE;
- $output = l($element['#title'], $element['#href'], $element['#localized_options']);
- return '
' . $output . $sub_menu . "
\n";
+ $variables['sub_menu'] = $element['#below'];
+ $variables['link'] = array(
+ '#type' => 'link',
+ '#title' => $element['#title'],
+ '#href' => $element['#href'],
+ '#options' => $element['#localized_options'],
+ );
+ $variables['attributes'] = $element['#attributes'];
}
/**
- * Returns HTML for a single local task link.
+ * Prepares variables for single local task link templates.
+ *
+ * Default template: menu-local-task.html.twig.
*
- * @param $variables
+ * @param array $variables
* An associative array containing:
* - element: A render element containing:
* - #link: A menu link array with 'title', 'href', and 'localized_options'
* keys.
* - #active: A boolean indicating whether the local task is active.
- *
- * @ingroup themeable
*/
-function theme_menu_local_task($variables) {
+function template_preprocess_menu_local_task(&$variables) {
$link = $variables['element']['#link'];
$link += array(
'localized_options' => array(),
@@ -284,6 +276,7 @@ function theme_menu_local_task($variables) {
if (!empty($variables['element']['#active'])) {
// Add text to indicate active tab for non-visual users.
$active = '' . t('(active tab)') . '';
+ $variables['attributes']['class'] = array('active');
// 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().
@@ -295,29 +288,36 @@ function theme_menu_local_task($variables) {
}
$link['localized_options']['set_active_class'] = TRUE;
+ $variables['link'] = array(
+ '#type' => 'link',
+ '#title' => $link_text,
+ '#options' => $link['localized_options'],
+ );
+
if (!empty($link['href'])) {
// @todo - remove this once all pages are converted to routes.
- $a_tag = l($link_text, $link['href'], $link['localized_options']);
+ $variables['link']['#href'] = $link['href'];
}
else {
- $a_tag = \Drupal::l($link_text, $link['route_name'], $link['route_parameters'], $link['localized_options']);
+ $variables['link'] += array(
+ '#route_name' => $link['route_name'],
+ '#route_parameters' => $link['route_parameters'],
+ );
}
-
- return '
' . $a_tag . '
';
}
/**
- * Returns HTML for a single local action link.
+ * Prepares variables for single local action link templates.
+ *
+ * Default template: menu-local-action.html.twig.
*
- * @param $variables
+ * @param array $variables
* An associative array containing:
* - element: A render element containing:
* - #link: A menu link array with 'title', 'href', and 'localized_options'
* keys.
- *
- * @ingroup themeable
*/
-function theme_menu_local_action($variables) {
+function template_preprocess_menu_local_action(&$variables) {
$link = $variables['element']['#link'];
$link += array(
'href' => '',
@@ -328,19 +328,24 @@ function theme_menu_local_action($variables) {
$link['localized_options']['attributes']['class'][] = 'button-action';
$link['localized_options']['set_active_class'] = TRUE;
- $output = '
';
+ $variables['link'] = array(
+ '#type' => 'link',
+ '#title' => $link['title'],
+ '#options' => $link['localized_options'],
+ );
+
// @todo Remove this check and the call to l() when all pages are converted to
// routes.
// @todo Figure out how to support local actions without a href properly.
if ($link['href'] === '' && !empty($link['route_name'])) {
- $output .= Drupal::l($link['title'], $link['route_name'], $link['route_parameters'], $link['localized_options']);
+ $variables['link'] += array(
+ '#route_name' => $link['route_name'],
+ '#route_parameters' => $link['route_parameters'],
+ );
}
else {
- $output .= l($link['title'], $link['href'], $link['localized_options']);
+ $variables['link']['#href'] = $link['href'];
}
- $output .= "
";
-
- return $output;
}
/**
@@ -561,36 +566,6 @@ function menu_local_tabs() {
}
/**
- * Returns HTML for primary and secondary local tasks.
- *
- * @param $variables
- * An associative array containing:
- * - primary: (optional) An array of local tasks (tabs).
- * - secondary: (optional) An array of local tasks (tabs).
- *
- * @ingroup themeable
- * @see menu_local_tasks()
- */
-function theme_menu_local_tasks(&$variables) {
- $output = '';
-
- if (!empty($variables['primary'])) {
- $variables['primary']['#prefix'] = '