Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
While paths can be altered, link attributes can't.
Proposed resolution
Add hook_link_alter, similar to D8.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#4 | interdiff.txt | 1.35 KB | chx |
#4 | 2562731_4.patch | 3.37 KB | chx |
Comments
Comment #2
chx CreditAttribution: chx commentedComment #3
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedMissing '&' before $text.
Comment #4
chx CreditAttribution: chx commentedAlso added a note about how hook_url_outbound_alter is better for $path .
Comment #5
chx CreditAttribution: chx at Tag1 Consulting commentedFixing credit.
Comment #6
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedRTBC, I don't think we need tests for this little change.
Comment #7
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedMy understanding is that this kind of use case is one of the reasons l() was made themable... Via a theme preprocess function or similar, you should be able to alter anything you want to here.
Of course that's an expensive thing to do performance-wise, but the expense comes only for the sites that need it, whereas a drupal_alter() call isn't totally free and impacts the majority of sites that won't ever use it. Plus it adds some extra complexity to what is already a complex area of the code...
I know there are also concerns with l() getting called too early in the bootstrap and triggering the theme system too early, but that should be possible to fix in #2086335: Bootstrap issue with theme initialization causes hook_custom_theme() never to be invoked.
Overall I think this change needs more review; I'm not totally sure that it's justified.
Comment #8
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedWe maybe could make hook_link_alter() optionally enabled via a $settings parameter?
Theme Link via preprocess is not the right thing here as it bundles the fast link system to the (in comparison) very slow theme system.