Problem/Motivation

Using last ui_patterns dev 2.0.x version 0d3fa1445108d92f17d6ba46de26a6fec3b70a1c commit and layout_paragraphs 2.0.1, in a fresh install, when i select a layout (called section in screencast), default selected layout is offcanvas which has variants.
Bootstrap grid with columns don't have variants.

When i select a bootstrap grid, \Drupal\ui_patterns\Element\ComponentFormBase::getComponent() get component id from default value (offcanvas) instead of selected #component_id ( bootstrap grid_row_2).

  /**
   * Helper function to return the component.
   */
  protected static function getComponent(array $element): Component | NULL {
    $component_id = $element['#default_value']['component_id'] ?? $element['#component_id'] ?? NULL;
    /** @var \Drupal\Core\Theme\ComponentPluginManager $component_plugin_manager */
    $component_plugin_manager = \Drupal::service("plugin.manager.sdc");
    return $component_id ? $component_plugin_manager->find($component_id) : NULL;
  }

Causes :

TypeError: Drupal\ui_patterns\Element\ComponentFormBase::getSources(): Argument #2 ($definition) must be of type array, null given, called in /var/www/html/web/modules/contrib/ui_patterns/src/Element/ComponentPropForm.php on line 88 in Drupal\ui_patterns\Element\ComponentFormBase::getSources() (line 155 of modules/contrib/ui_patterns/src/Element/ComponentFormBase.php). 

Switching the two conditions fixes it, but i don't think this is the right way to do it.

  /**
   * Helper function to return the component.
   */
  protected static function getComponent(array $element): Component | NULL {
    $component_id = $element['#component_id'] ?? $element['#default_value']['component_id'] ?? NULL;
    /** @var \Drupal\Core\Theme\ComponentPluginManager $component_plugin_manager */
    $component_plugin_manager = \Drupal::service("plugin.manager.sdc");
    return $component_id ? $component_plugin_manager->find($component_id) : NULL;
  }

$definition is NULL because loaded component is the offcanvas component which has variants, but we are trying to get variant prop from grid row component which has no variant in its definition.

Command icon 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

goz created an issue. See original summary.

pdureau’s picture

Title: Component id is wrong selecting layout with layout_paragraph » [2.0.x] Component id is wrong selecting layout with layout_paragraph

goz’s picture

Status: Active » Needs review
pdureau’s picture

Assigned: Unassigned » just_like_good_vibes

Mikael did most of ComponentFormBase so he will be the most suited for the review

pdureau’s picture

Title: [2.0.x] Component id is wrong selecting layout with layout_paragraph » [2.0.5] Component id is wrong selecting layout with layout_paragraph

just_like_good_vibes made their first commit to this issue’s fork.

just_like_good_vibes’s picture

i am still hesitant because the bug seems triggered by the usage of ui_patterns_ui, and we are trying to fix it in ui_patterns.

pdureau’s picture

Title: [2.0.5] Component id is wrong selecting layout with layout_paragraph » [2.0.6] Component id is wrong selecting layout with layout_paragraph
pdureau’s picture

Title: [2.0.6] Component id is wrong selecting layout with layout_paragraph » [2.0.7] Component id is wrong selecting layout with layout_paragraph
just_like_good_vibes’s picture

i found this line in ui_patterns_ui (UiPComponentFormDisplaysForm)

$component_id = $element['#component_id'] ?? $element['#default_value']['component_id'] ?? NULL;

and we have this line in ui_patterns (ComponentFormBase)

$component_id = $element['#default_value']['component_id'] ?? $element['#component_id'] ?? NULL;

we need to sort this out

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » Unassigned
Status: Needs review » Reviewed & tested by the community

just_like_good_vibes’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.