The example of hook_link_alter
is not working because route_name
variable is not passed to this hook. I suppose route name should be obtained from url
variable instead.
function hook_link_alter(&$variables) {
// Add a warning to the end of route links to the admin section.
if (isset($variables['route_name']) && strpos($variables['route_name'], 'admin') !== FALSE) {
$variables['text'] = t('@text (Warning!)', [
'@text' => $variables['text'],
]);
}
}
Issue fork drupal-3204353
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
pragati_kanade CreditAttribution: pragati_kanade at QED42 for Drupal India Association commentedComment #4
pragati_kanade CreditAttribution: pragati_kanade at QED42 for Drupal India Association commentedComment #6
longwaveThanks for working on this! The code improvement is good but we don't need the additional comment, we can just use a single-line @var comment to denote the variable type.
Comment #8
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedMade changes as per comment #6.
Comment #9
longwaveThanks!
Comment #12
catchCommitted/pushed to 9.2.x and cherry-picked to 8.9.x, thanks!
Comment #14
wombatbuddy CreditAttribution: wombatbuddy commentedI'm not sure that this is the right place to the issue I have discovered, but it looks related. The documentation page for Drupal 10 still has the wrong example: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Utility%2...
The file "core/lib/Drupal/Core/Utility/link.api.php" referenced by the documentation does not exist.
Also, the link to non-existent file "core/lib/Drupal/Core/Utility/link.api.php" is present on the page with hooks list: https://api.drupal.org/api/drupal/core%21core.api.php/group/hooks/10
Comment #15
Chi CreditAttribution: Chi commentedThat happened because #2808577: Move hook_link_alter documentation to core/lib/Drupal/Core/Utility/link.api.php copied old hook code to link.api.php.
@wombatbuddy can you create an issue for this?