#16724 closed enhancement (duplicate)
Add current-menu-item to custom links that only contains path
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 3.0 |
| Component: | Menus | Keywords: | has-patch |
| Focuses: | Cc: |
Description
It is possible to add a custom link to a menu with a URL that only contains a path, such as "/contact". The link will work properly, but the menu item will not receive the current-menu-item class when that page is active.
The supplied patch (current-menu-item-custom-link-path.diff) allows the current-menu-item class to be applied to the path-only custom links by prepending the current request's scheme and domain to the link, turning it into a complete URL, before running the check.
The patch considers a link as an incomplete URL if it begins with a forward-slash (/). This way, complete URLs (which will always begin with a letter from the scheme) will be unmodified.
Attachments (1)
Change History (6)
#3
@
15 years ago
If you are talking about having links to network locations such as //host/path, I'm not sure that needs to be a concern.
This section of code and the $item_url variable being modified are only for determining the classes to attribute to the different menu elements. So, even if there is an off chance that such a link could be improperly gain the current-menu-item class, this will do nothing to affect functionality.
I tested by adding a custom link with a URL of //contact (since I have a page at /contact). I then navigated to the contact page and found that the contact page menu item had the current-menu-item class as expected and that the //contact menu item did not have this class. This is because the //contact link is being changed to http://domain/other-path//contact which will not match http://domain/other-path/contact.
Even if someone navigates to http://domain/other-path//contact manually, the redirect_canonical function takes care of redirecting to http://domain/other-path/contact/ so that even this will fail to add the current-menu-item class to the //contact link.
Is there some angle that I haven't account for that will still cause an issue?
Note that this would break scheme-agnostic
//-style links.