Skip to content

Fix Home active state on front page (closes #768)#769

Merged
drale1 merged 3 commits into8.xfrom
Drale1/8.x/#768-Home-menu-item-does-not-get-active-state-on-front-page-in-Drupal-10
Feb 26, 2026
Merged

Fix Home active state on front page (closes #768)#769
drale1 merged 3 commits into8.xfrom
Drale1/8.x/#768-Home-menu-item-does-not-get-active-state-on-front-page-in-Drupal-10

Conversation

@drale1
Copy link
Collaborator

@drale1 drale1 commented Feb 13, 2026

Linked issues

Solution

Fixes Home menu item not receiving active state on front page in Drupal 10.
Problem: When the front page is set to a node path (e.g., /node/1), the Home menu item (pointing to /) was not marked as active because the path comparison (/node/1 vs /) failed.
Fix: Added a front page check in the menu active trail detection logic. When on the front page, menu items pointing to / are now correctly marked as active, matching the behavior of other menu items.
This ensures consistent navigation styling across all menu items, including Home, when users are on the homepage.
Testing: Verified on Drupal 10.6.2. Works correctly in Drupal 11 (no changes needed there).

Checklist

  • I have read the CONTRIBUTING.md document.
  • My commit messages follow the contributing standards and style of this project.
  • My code follows the coding standards and style of this project.
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Need to run update.php after code changes
  • Requires a change to end-user documentation.
  • Requires a change to developer documentation.
  • Requires a change to QA tests.
  • Requires a new QA test.
  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@drale1 drale1 requested a review from jjroelofs February 13, 2026 11:48
- Move isFrontPage() call from recursive function to caller to avoid
  redundant service calls on each recursion level
- Remove unnecessary empty string check for item path
Copy link
Collaborator

@jjroelofs jjroelofs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened #770 targeting your branch with two suggested changes:

  1. Performance: isFrontPage() is moved out of the recursive dxpr_theme_menu_set_active_trail() into the caller and passed as a parameter — avoids redundant service calls on every recursion level.
  2. Simplification: Removed the $item_path === '' check — Drupal's <front> route resolves to / via Url::toString(), so only / needs matching.

I haven't tested these changes, so please verify on your end that:

  • Home menu item still gets active state on the front page (Drupal 10)
  • Other menu items retain correct active states
  • Nested menus still correctly propagate the active trail

If everything works, feel free to merge #770 into your branch and then merge your PR into 8.x without requesting re-review.

…state

Simplify front page active state check and fix performance
@drale1 drale1 merged commit 6fdcfb6 into 8.x Feb 26, 2026
3 checks passed
@drale1
Copy link
Collaborator Author

drale1 commented Feb 26, 2026

@jjroelofs
Merged #770 and tested locally. Home and all other menu items get the active state as expected; nested menus propagate the trail correctly. Merging into 8.x. Thanks for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants