Navigation: Fix bug in calculating the active menu item #49195
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Fixes #49153
Why?
As described in #49153, when a post and a term have the same ID and both exist in the menu, the code that determines the active menu item is wrong. As a result, both the term and the post get marked as active because we only check the ID and not the context.
How?
Tweaking the check to determine if a menu item is active.
$attributes['kind']
can be things liketaxonomy
,post-type
etc. Usingget_queried_object()
in a term will return an object which will have thetaxonomy
defined. In a post, thepost_type
will be defined and so on.This PR will check that the ID is the same, AND that the context (post/term etc) is right before marking a menu item as active.
Testing Instructions
Before the PR, visiting the term will highlight both the post and the term as active, and the same will happen when visiting the page.
After the PR, the
current-menu-item
class will only be added to the right element.Note: The same code was applied both to the
navigation-link
and thenavigation-submenu
blocks since they were using identical checks.Testing Instructions for Keyboard
Not applicable.