OEL-4322: Migrate Alert and Description list components.#528
OEL-4322: Migrate Alert and Description list components.#528piotrsmykaj wants to merge 1 commit intoepic/OEL-3864from
Conversation
f941bc5 to
c5df227
Compare
| {% endfor %} | ||
|
|
||
| {% set _items = _items|merge([item|merge({'term': _terms})]) %} | ||
| {% endfor %} |
There was a problem hiding this comment.
Could this be simplified by using |map(..)?
(on two levels)
The AI gives me this:
{% set _items = items|map(item =>
item|merge({
terms: (item.term is iterable ? item.term : [item.term])|map(term => {
_term = term is iterable ? term : {'label': term}
} => _term.icon is defined and _term.icon
? _term|merge({
icon: {
size: 'xs',
path: _icon_path
}|merge(_term.icon is iterable ? _term.icon : { name: _term.icon })
})
: _term
)
})
) %}I am not saying this will work as-is, just as a starting point to explore.
There was a problem hiding this comment.
We could also create twig functions or filters if that helps. Either generic helpers, or more specific functions aimed at specific templates.
But not sure it would be worthwhile in this case.
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
I see we are removing the preprocess, but the pattern itself is still there.
| {# 'items': items,#} | ||
| {# 'attributes': attributes,#} | ||
| {# })#} | ||
| {#}}#} |
There was a problem hiding this comment.
Is this necessary?
As a result, no menu will be shown?
We should find a different solution where we don't have to edit individual templates like this.
| } | ||
|
|
||
| $data['#fields']['image'] = ImageValueObject::fromArray($data['#fields']['image']); | ||
|
|
There was a problem hiding this comment.
Usually I like this early return pattern.
In this case I am not fully on board, because:
The method name massageCardPatterns() suggests that any alteration of the data for this pattern would happen in this method. For now it is only about items, but what if we want to also alter something else? Going by the method name, it would go into the same method.
private static function massageCardPattern(array $data): array {
if (isset($data['#fields']['image'])) {
$data['#fields']['image'] = ImageValueObject::fromArray($data['#fields']['image']);
}
if (isset($data['label'])) {
$data['label'] = translate($data['label']);
}
return $data;
}It's not a hard blocker, I am just sharing my thoughts.
| if (!isset($data['#fields']['items'])) { | ||
| return $data; | ||
| } | ||
|
|
There was a problem hiding this comment.
Here the same arguments apply to the "early return", but I kind of like it because we don't have to touch the rest of the method for indentation :)
No description provided.