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
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3614019.patch | 502 bytes | manuel.loth |
Issue fork ui_suite_dsfr-3614019
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
Comment #2
manuel.loth commentedComment #3
manuel.loth commentedComment #4
just_like_good_vibesthank you very much for reporting @manuel.loth, i will work that one now.
Comment #6
manuel.loth commentedComment #7
just_like_good_vibesComment #8
manuel.loth commentedThanks. The fix is ok to me.
However, I noticed the same problem on the button component. You may want to fix that as well.
Comment #10
just_like_good_vibes