hook_link_alter() wrong example

Created on 18 March 2021, over 3 years ago
Updated 15 September 2023, about 1 year ago

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'],
    ]);
  }
}
🐛 Bug report
Status

Fixed

Version

9.1

Component
Other 

Last updated about 7 hours ago

Created by

🇷🇺Russia Chi

Live updates comments and jobs are added and updated live.
  • Documentation

    Primarily changes documentation, not code. For Drupal core issues, select the Documentation component instead of using this tag. In general, component selection is preferred over tag selection.

  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024