Problem/Motivation
https://git.drupalcode.org/project/ui_patterns/-/blob/2.0.x/src/Element/... has this method:
/**
* Process stories slots.
*
* Stories slots have no "#" prefix in render arrays. Let's add them.
* A bit like UI Patterns 1.x's PatternPreview::getPreviewMarkup()
* This method belongs here because used by both ui_patterns_library and
* ui_patterns_legacy.
*/
public function processStoriesSlots(array $slots): array {
foreach ($slots as $slot_id => $slot) {
if (!is_array($slot)) {
continue;
}
if (array_is_list($slot)) {
$slots[$slot_id] = $this->processStoriesSlots($slot);
}
$slot_keys = array_keys($slot);
$render_keys = ["theme", "type", "markup", "plain_text"];
if (count(array_intersect($slot_keys, $render_keys)) > 0) {
foreach ($slot as $key => $value) {
if (is_array($value)) {
$value = $this->processStoriesSlots($value);
}
if (str_starts_with($key, "#")) {
continue;
}
$slots[$slot_id]["#" . $key] = $value;
unset($slots[$slot_id][$key]);
}
}
}
return $slots;
}
However, some recent examples showed this rule is too naive and simple. For example, with a html_tag render element, we don't want the children to get the # prefix
Proposed resolution
- Move the logic to its own service under ui_patterns_library (so, ui_patterns_library is becoming a dependency of ui_patterns_legacy)
- Fix the logic
Issue fork ui_patterns-3477573
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
pdureau commentedComment #4
pdureau commentedComment #5
pdureau commentedComment #6
grimreaperMinor code adjustments to discuss.
And needs tests.
Comment #7
pdureau commentedOK, I will move
$render_keysto a class CONST.Not sure about
$html_tag_allowed_render_keysbecause it is very specific to the internal logic of the condition.I personally don't like traits so much in PHP. But I will follow your recommendation if you tell me to use them.
I will do the test now
Comment #8
pdureau commentedComment #9
pdureau commentedTested with
ui_suite_bootstrapexamples. 2 issues.html_tag: order of keys
Having the html_tag workaround children at the beginning doesn't work:
We need to have it at the end:
Proposal:
Skip integers children
Comment #10
pdureau commentedComment #11
pdureau commentedComment #12
pdureau commentedI have added unit tests.
Comment #13
grimreaperComment #15
pdureau commented