[2.0.0-beta4] Performance of SourcePluginManager

Created on 28 September 2024, about 2 months ago

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

  1. Move the logic to its own service under ui_patterns_library.
  2. Fix the logic
🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France pdureau Paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024