Problem/Motivation

When using a Link component on an external URL without specifying the 'title' attribute, the rendering crashes when on a Drupal 11 site :
TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/html/web/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 433 of core/lib/Drupal/Component/Utility/Html.php).

Steps to reproduce

Using the render API, insert a Link component :

$build['a-link'] = [
  '#type' => 'component',
  '#component' => 'ui_suite_dsfr:link',
  '#slots' => [
    'label'=> 'Wikipedia',
  ],
  '#props' => [
    'external' => TRUE,
    'url' => Url::fromUri('https://fr.wikipedia.org'),
  ],
];

The problem is avoided by specifying an empty string for the 'title' prop:

$build['a-link'] = [
  '#type' => 'component',
  '#component' => 'ui_suite_dsfr:link',
  '#slots' => [
    'label'=> 'Wikipedia',
  ],
  '#props' => [
    'external' => TRUE,
    'url' => Url::fromUri('https://fr.wikipedia.org'),
    'title' => '',
  ],
];

Proposed resolution

The problem occurs when concataining ' - new window' to the title, using a TranslatableMarkup.
TranslatableMarkup does not allow null values anymore for placeholders. The value of the title attribute should be coerced to an empty string when null, or the case should be treated separately.

Attached is a proposed resolution, that also addresses another issue : 'new window' is not translated.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#6 3614019.patch502 bytesmanuel.loth
Command icon 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

manuel.loth created an issue. See original summary.

manuel.loth’s picture

Issue summary: View changes
manuel.loth’s picture

Issue summary: View changes
just_like_good_vibes’s picture

Assigned: Unassigned » just_like_good_vibes

thank you very much for reporting @manuel.loth, i will work that one now.

manuel.loth’s picture

Issue summary: View changes
StatusFileSize
new502 bytes
just_like_good_vibes’s picture

Assigned: just_like_good_vibes » Unassigned
Status: Active » Needs review
manuel.loth’s picture

Thanks. The fix is ok to me.
However, I noticed the same problem on the button component. You may want to fix that as well.

just_like_good_vibes’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.