Use the correct placeholder for "href" attributes

Created on 1 July 2024, 10 months ago
Updated 16 July 2024, 9 months ago

Some methods/functions use code similar to the following one.

$build['description'] = [
  '#markup' => $this->t('Content Entity Example implements a Contacts model. These contacts are fieldable entities. You can manage the fields on the <a href="@adminlink">Contacts admin page</a>.', [
    '@adminlink' => $this->urlGenerator->generateFromRoute('content_entity_example.contact_settings'),
  ]),
];

The placeholder used for the href attribute is @variable, while the correct one would be :variable, as reported on FormattableMarkup::placeholderFormat().

:variable: Return value is escaped with \Drupal\Component\Utility\Html::escape() and filtered for dangerous protocols using UrlHelper::stripDangerousProtocols(). Use this when using the "href" attribute, ensuring the attribute value is always wrapped in quotes

Any occurrence of <a href="@ in translatable strings must be replaced with <a href=":

📌 Task
Status

Fixed

Version

4.0

Component

Code

Created by

🇮🇹Italy apaderno Brescia, 🇮🇹

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024