Something went wrong on our end
-
Eric Bremner authoredEric Bremner authored
navigation.inc 1.03 KiB
<?php
/**
* @file
* Navigation template functions.
*/
use Drupal\Component\Utility\Html;
/**
* Implements hook_reprocess_menu_local_tasks().
*/
function gesso_preprocess_menu_local_tasks(&$variables) {
foreach (['primary', 'secondary'] as $type) {
$tabs = [];
// Sort the tabs by #weight.
uasort(
$variables[$type],
[
'Drupal\Component\Utility\SortArray',
'sortByWeightProperty',
]
);
foreach (array_keys($variables[$type]) as $key) {
// Add the tab to a new array.
$tabs[$key] = [
'active' => $variables[$type][$key]['#active'],
'url' => $variables[$type][$key]['#link']['url']->toString(),
'text' => Html::escape($variables[$type][$key]['#link']['title']),
];
// Check if the tab should be shown by rendering the original.
$link = \Drupal::service('renderer')->render($variables[$type][$key]);
if (!$link) {
unset($tabs[$key]);
}
}
// Overwrite the original tabs data.
$variables[$type] = $tabs;
}
}