- πΊπΈUnited States smustgrave
This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β as a guide.
Appears there was 1 open thread. @alexpott could that be closed?
- ππΊHungary mxr576 Hungary
This means that any alterations made to links must not vary based on anything other than what's already passed into the alter hook.
...and maybe this should be a valid limitation of the scope of the hook that shall not be bypassed. For every other use case, use a different approach and not this hook.
I had this issue open for months for sharing my 2 cents after I realized that some devs were using this hook to conditionally replace URLs of links generated by Drupal... like (conditionally) replacing the built-in login/log-out link in the menu with one that points to SSO. The issues were the same, cachebility information related to the new/altered link or the condition based on a link replaced/modified by our code could not be bubbled up.
The proper solution was in our case for this particular problem instead of using this hook, we defined a custom menu link and leveraged
hook_menu_links_discovered_alter()
to replace the original one. This approach supports cacheability bubble-up, even from access results (when the destination internal url is not available for the current user.) This also caused performance gain because a menu link was only calculated two times (for authenticated and anonymous) in contradiction with the hook_link_alter() that ran on all page requests (IIRC).So I tend to believe that instead of enhancing the capabilities of this hook rather the hook's documentation should be improved and be more explicit about that, as this is a front-end related alter hook, it should be only used for small "cosmetical" changes and for everything else a different approach should be used. (Like changing links at the source instead of trying to alter them close to the end of the rendering process.)