Problem/Motivation
In #3479850: [2.0.0-beta4] LinksPropType normalization minor update, it introduced:
protected static function normalizeLink(array $item): array {
...
if (!is_string($item["title"])) {
$item["title"] = (string) $item["title"];
}
In #3466028: Ensure media library popin is usable, I have a side effect compared with UIP1 + UIP settings due to: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/media...
$display_title = [
'#markup' => $this->t('<span class="visually-hidden">Show </span>@title<span class="visually-hidden"> media</span>', ['@title' => $title]),
];
// $display_title = $this->t('<span class="visually-hidden">Show </span>@title<span class="visually-hidden"> media</span>', ['@title' => $title]);
if ($allowed_type_id === $selected_type_id) {
$display_title = [
'#markup' => $this->t('<span class="visually-hidden">Show </span>@title<span class="visually-hidden"> media</span><span class="active-tab visually-hidden"> (selected)</span>', ['@title' => $title]),
];
// $display_title = $this->t('<span class="visually-hidden">Show </span>@title<span class="visually-hidden"> media</span><span class="active-tab visually-hidden"> (selected)</span>', ['@title' => $title]);
}
I have tested with the commented out line it is then ok.
I don't know why Core adds a depth level with #markup, but I get "Array" as link title...
I will search why this i done like that, otherwise I will create a core issue to remove this. But I think links prop type should handle this case because I guess It can still happen elsewhere.
EDIT: nothing found with a blame in core, this code part had been untouched since 5 years. So here is the core issue #3488583: Media library links: remove #markup
Steps to reproduce
Trigger normalize of media library links in a _preprocess_links__media_library_menu:
$variables['preprocessed_items'] = LinksPropType::normalize(\array_filter(
$variables['links'],
));
Proposed resolution
Check if title is a renderable array before cast?
Remaining tasks
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | Capture d’écran du 2024-11-21 16-31-33.png | 52.23 KB | grimreaper |
| #11 | Capture d’écran du 2024-11-21 14-39-42.png | 112.68 KB | grimreaper |
Issue fork ui_patterns-3488582
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
grimreaperComment #4
grimreaperI made a small change that fix my use case.
At least it can be used to open discussion.
Comment #5
pdureau commentedWe don't allow render arrays in prop values, so in links item titles.
Instead of skipping the cast to string, we may render the renderable instead.
Let's discuss
Comment #6
pdureau commentedComment #7
grimreaperJust made a quick call with @pdureau,
Let's add a normalize in StringPropType to handle those cases then call this normalize in LinksPropType.
Also use the occasion to potentially get rid of the normalizeAttributes method in LinksPropType to use directly the normalize of AttributesPropType.
Comment #8
grimreaperMR updated
Comment #9
pdureau commentedI see there were already a call to
AttributesPropType::normalize()inLinksPropType::normalize(), but you removed some apparently useless logic executed before. I hope it was not done like that in purpose.There are 3 phpunit failures in your MR:
Is it related to your change?
Also, maybe we can also move some string related logic (like
::normalizeObject()) fromAttributesPropType::normalize()toStringPropType::normalize()Comment #10
grimreaperYes, I think it is a duplicated logic part and the change will give an equivalent result.
The failures are due to the normalize in StringPropType.
Comment #11
grimreaperThe problem is that it is a render array that is passed and if rendered then later on, the
are escaped. That's why the tests are failing.
I currently don't know if I should adapt the normalize or it highlights an existing problem.
Comment #12
grimreaperI prefer to discuss it live when you will be back.
Comment #13
grimreaperOther side effect of normalizing link title into a string with ui_icons_menu.
Comment #14
pdureau commentedI have rebased and I got a look.
I got 2 phpunit error, but I don't know if it comes from the rebase or not:
Let's talk.
Comment #15
grimreaperComment #16
grimreaperComment #18
pdureau commentedComment #19
pdureau commented