You are here

protected function LinkGenerator::doGenerate in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Utility/LinkGenerator.php \Drupal\Core\Utility\LinkGenerator::doGenerate()
  2. 9 core/lib/Drupal/Core/Utility/LinkGenerator.php \Drupal\Core\Utility\LinkGenerator::doGenerate()

Generates the link.

Parameters

Drupal\Core\GeneratedLink $generated_link: The generated link, along with its associated cacheability metadata.

array $attributes: The attributes of the generated link.

array $variables: The link text, url, and other options.

Return value

Drupal\Core\GeneratedLink The generated link, along with its associated cacheability metadata.

File

core/lib/Drupal/Core/Utility/LinkGenerator.php, line 203

Class

LinkGenerator
Provides a class which generates a link with route names and parameters.

Namespace

Drupal\Core\Utility

Code

protected function doGenerate($generated_link, $attributes, $variables) {
  if (!$variables['text'] instanceof MarkupInterface) {
    $variables['text'] = Html::escape($variables['text']);
  }
  $attributes = new Attribute($attributes);

  // This is safe because Attribute does escaping and $variables['text'] is
  // either rendered or escaped.
  return $generated_link
    ->setGeneratedLink('<' . $generated_link::TAG . $attributes . '>' . $variables['text'] . '</' . $generated_link::TAG . '>');
}