Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/modules/link_generation_test/link_generation_test.module \link_generation_test_link_alter()
  2. 9 core/modules/system/tests/modules/link_generation_test/link_generation_test.module \link_generation_test_link_alter()

Implements hook_link_alter().

1 string reference to 'link_generation_test_link_alter'
LinkGenerationTest::testHookLinkAlter in core/tests/Drupal/KernelTests/Core/Url/LinkGenerationTest.php
Tests how hook_link_alter() can affect escaping of the link text.

File

core/modules/system/tests/modules/link_generation_test/link_generation_test.module, line 11
Helper module for the link generation tests.

Code

function link_generation_test_link_alter(&$variables) {
  if (\Drupal::state()
    ->get('link_generation_test_link_alter', FALSE)) {

    // Add a text to the end of links.
    if (\Drupal::state()
      ->get('link_generation_test_link_alter_safe', FALSE)) {
      $variables['text'] = t('@text <strong>Test!</strong>', [
        '@text' => $variables['text'],
      ]);
    }
    else {
      $variables['text'] .= ' <strong>Test!</strong>';
    }
  }
}