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

CommentFileSizeAuthor
#4 interdiff.txt1.35 KBchx
#4 2562731_4.patch3.37 KBchx
#2 2562731_1.patch3.14 KBchx
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx created an issue. See original summary.

chx’s picture

FileSize
3.14 KB
Fabianx’s picture

+++ b/modules/system/system.api.php
@@ -4331,6 +4331,53 @@ function hook_url_outbound_alter(&$path, &$options, $original_path) {
+function hook_link_alter($text, &$path, &$options) {

Missing '&' before $text.

chx’s picture

FileSize
3.37 KB
1.35 KB

Also added a note about how hook_url_outbound_alter is better for $path .

chx’s picture

Fixing credit.

Fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC, I don't think we need tests for this little change.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs subsystem maintainer review

My 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.

Fabianx’s picture

We 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.