Skip to content

Commit 56a20d5

Browse files
committed
Merge branch '11.x' of https://github.com/SU-SWS/stanford_profile into SWSDEVOPS-150-trustee-profile-update
2 parents 4eb9cac + e803ada commit 56a20d5

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

themes/stanford_basic/stanford_basic.theme

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,8 @@ function stanford_basic_preprocess_menu(&$variables, $hook) {
420420
if ($variables['menu_name'] !== "main") {
421421
return;
422422
}
423-
foreach ($variables['items'] as &$item) {
424-
$menu_item = [$item];
425-
_stanford_basic_menu_process_submenu($menu_item, $current_path);
426-
$item = $menu_item[0];
427-
}
423+
424+
_stanford_basic_menu_process_submenu($variables['items'], $current_path);
428425
if (theme_get_setting('nav_dropdown_enabled', 'stanford_basic')) {
429426
$variables['attributes']['class'][] = 'su-multi-menu--dropdowns';
430427
}
@@ -442,21 +439,19 @@ function stanford_basic_preprocess_menu(&$variables, $hook) {
442439
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
443440
*/
444441
function _stanford_basic_menu_process_submenu(&$submenu, $current_path) {
442+
$is_front = \Drupal::service('path.matcher')->isFrontPage();
443+
445444
foreach ($submenu as &$item) {
446-
$item_path = (is_string($item['url'])) ? $item['url'] : $item['url']->toString(TRUE)->getGeneratedUrl();
447-
$is_front = \Drupal::service('path.matcher')->isFrontPage();
448-
if (
449-
$item_path == $current_path ||
450-
(_stanford_basic_path_is_home($item_path) && $is_front)
451-
) {
445+
$item_path = is_string($item['url']) ? $item['url'] : $item['url']->toString(TRUE)->getGeneratedUrl();
446+
if ($item_path == $current_path || (_stanford_basic_path_is_home($item_path) && $is_front)) {
452447
$item['is_active'] = TRUE;
453448
}
454449

455450
if ($item['url'] instanceof Url && !_stanford_basic_link_is_public($item['url'])) {
456451
$item['unpublished'] = TRUE;
457452
}
458453

459-
if ($item['in_active_trail'] && count($item['below'])) {
454+
if (!empty($item['below'])) {
460455
_stanford_basic_menu_process_submenu($item['below'], $current_path);
461456
}
462457
}
@@ -472,6 +467,11 @@ function _stanford_basic_menu_process_submenu(&$submenu, $current_path) {
472467
* TRUE if the path corresponds to the current home page.
473468
*/
474469
function _stanford_basic_path_is_home(string $path) {
470+
$is_home = &drupal_static(__FUNCTION__);
471+
if (!is_null($is_home)) {
472+
return $is_home;
473+
}
474+
475475
// account for weird paths in input
476476
$normal_path = strtolower(trim($path));
477477
$config = \Drupal::config('system.site');
@@ -484,9 +484,11 @@ function _stanford_basic_path_is_home(string $path) {
484484
$normal_path == $alias ||
485485
$normal_path == '<front>'
486486
) {
487-
return TRUE;
487+
$is_home = TRUE;
488+
return $is_home;
488489
}
489-
return FALSE;
490+
$is_home = FALSE;
491+
return $is_home;
490492
}
491493

492494
/**

0 commit comments

Comments
 (0)