Problem/Motivation

1: In https://git.drupalcode.org/project/ui_patterns/-/blob/2.0.x/modules/ui_p...

  public function build() {
    $build = $this->buildComponentRenderable();
    return $build;
  }

  public function blockForm($form, FormStateInterface $form_state) {
    return $this->buildComponentsForm($form_state);
  }

  public function blockSubmit($form, FormStateInterface $form_state) {
    $this->submitComponentsForm($form_state);
  }

$form should be passed to the ComponentFormBuilderTrait methods, and/or the return of those methods should only target a key in $form and not replacing it entirely.

Not taking the provided $form into account may lead to extensibility problems if someone alters the form in other contrib or custom.

I had a problem years ago in a field formatter plugin where I had not called a parent method, it was ok in "manage display" but ot in layout builder because it was preparing additional stuff: https://git.drupalcode.org/project/file_extractor/-/commit/cf3b74dcc1312...

That's why I think not taking the provided $form into account may lead to problems.

2: In https://git.drupalcode.org/project/ui_patterns/-/blob/2.0.x/src/Form/Com...

  protected function getComponentConfiguration(): array {
    return $this->configuration['ui_patterns'] ?? [];
  }

  protected function setComponentConfiguration($configuration): void {
    $this->configuration['ui_patterns'] = $configuration;
  }

  ...

I think the "ui_patterns" key should be transformed into an argument, in case a form needs multiple component form elements.

3: In https://git.drupalcode.org/project/ui_patterns/-/blob/2.0.x/src/Form/Com...

  public function buildComponentRenderable($component_id = NULL, $source_contexts = []) {

This method is used for rendering, the trait is named ComponentFormBuilderTrait, maybe it should be placed in another trait? I understand that it is there because it is using the common method "$this->getComponentConfiguration()".

Proposed resolution

Remaining tasks

API changes

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

Grimreaper created an issue. See original summary.

pdureau’s picture

Title: ComponentFormBuilder: make it more dynamic » [2.0.0-alpha3] ComponentFormBuilder: make it more dynamic
pdureau’s picture

Title: [2.0.0-alpha3] ComponentFormBuilder: make it more dynamic » [2.0.0-beta1] ComponentFormBuilder: make it more dynamic
pdureau’s picture

Assigned: Unassigned » christian.wiedemann

To have a look

christian.wiedemann’s picture

1. This is done wrong in Block Source which we propably remove.
2. I am not sure about that. Actually I think it is good to have allways the same key in every consumer. We may provide a getConfigurationKey() function to overwrite that? Should we? @pdureau @Grimreaper
3. Should we provide an own trait for that? I would vote for that- @pdureau @Grimreaper

christian.wiedemann’s picture

Status: Active » Needs work
pdureau’s picture

Assigned: christian.wiedemann » grimreaper
Status: Needs work » Postponed (maintainer needs more info)

This is done wrong in Block Source which we propably remove.

We have an issue about that: #3460784: [2.0.0-beta1] Blocks implementing PluginFormInterface don't work with BlockSource
We will not remove BlockSource but introduce a whitelist.

2. I am not sure about that. Actually I think it is good to have allways the same key in every consumer. We may provide a getConfigurationKey() function to overwrite that? Should we? @pdureau @Grimreaper
3. Should we provide an own trait for that? I would vote for that- @pdureau @Grimreaper

No opinion. I assign to @Grimreaper

grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Postponed (maintainer needs more info) » Needs work

Hi,

1. Now that BlockForm return $form that is passed to it, no problem.
2. I opened a MR with a POC of what I had in mind and with current codebase. I have just edited the files, not tested. This can be used to discuss.
3. Vote for a new trait too.

pdureau’s picture

Assigned: Unassigned » christian.wiedemann
christian.wiedemann’s picture

@Grimreaper I tested your code and add the configuration_id to all places. From my point of view it should work now. (But we realy need e2e tests now)

christian.wiedemann’s picture

Status: Needs work » Needs review
pdureau’s picture

Florent, can you have a look?

grimreaper’s picture

Assigned: grimreaper » christian.wiedemann
Status: Needs review » Needs work

@Christian.wiedemann,

Thanks for the update.

I put some code review comments.

Also point 3, creating a new trait remains to be done.

christian.wiedemann’s picture

@Grimreaper I updated/fixed your comments. We decided to no implement an own trait for rendering because they belong somehow together. Thanks!

christian.wiedemann’s picture

Status: Needs work » Needs review
pdureau’s picture

grimreaper’s picture

Hi,

@Christian.wiedemann, thanks for your work. Ok for me now.

I have rebased and removed the todo.

You can give a last review in case my rebase broke stuff.

christian.wiedemann’s picture

Rebase was the hell. So I created a merge branch and opened a pull request. I tested Views Layouts and Field formatters. We should merge it.

https://git.drupalcode.org/issue/ui_patterns-3444770/-/tree/3444770-2.0....

pdureau’s picture

Status: Needs review » Needs work

Hi Christian,

So I created a merge branch and opened a pull request.

So, this one? https://git.drupalcode.org/project/ui_patterns/-/merge_requests/180

I am not very comfortable about opening a new branch, instead of doing the rebase. I guess rebase was hell because it was done late. So, I will ash @grimreaper to have a look, because I don't feel competent enough in this subject.

However, before that, it seems phpstan check has failed: https://git.drupalcode.org/project/ui_patterns/-/jobs/2407677

  Line   src/Form/ComponentFormBuilderTrait.php (in context of class                                                          
         Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter\ComponentFormatterBase)                              
  121    Method                                                                                                               
         Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter\ComponentFormatterBase::getComponentConfiguration()  
         invoked with 1 parameter, 0 required.                                                                                
  159    Method                                                                                                               
         Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter\ComponentFormatterBase::getComponentConfiguration()  
         invoked with 1 parameter, 0 required.                                                                                
  192    Method                                                                                                               
         Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter\ComponentFormatterBase::getComponentConfiguration()  
         invoked with 1 parameter, 0 required.                                                                                

  Line   src/Form/ComponentFormBuilderTrait.php (in context of class                          
         Drupal\ui_patterns_views\Plugin\views\row\ComponentRow)                              
  121    Method                                                                               
         Drupal\ui_patterns_views\Plugin\views\row\ComponentRow::getComponentConfiguration()  
         invoked with 1 parameter, 0 required.                                                
  159    Method                                                                               
         Drupal\ui_patterns_views\Plugin\views\row\ComponentRow::getComponentConfiguration()  
         invoked with 1 parameter, 0 required.                                                
  192    Method                                                                               
         Drupal\ui_patterns_views\Plugin\views\row\ComponentRow::getComponentConfiguration()  
         invoked with 1 parameter, 0 required.                                                

  Line   src/Form/ComponentFormBuilderTrait.php (in context of class                              
         Drupal\ui_patterns_views\Plugin\views\style\ComponentStyle)                              
  121    Method                                                                                   
         Drupal\ui_patterns_views\Plugin\views\style\ComponentStyle::getComponentConfiguration()  
         invoked with 1 parameter, 0 required.                                                    
  159    Method                                                                                   
         Drupal\ui_patterns_views\Plugin\views\style\ComponentStyle::getComponentConfiguration()  
         invoked with 1 parameter, 0 required.                                                    
  192    Method                                                                                   
         Drupal\ui_patterns_views\Plugin\views\style\ComponentStyle::getComponentConfiguration()  
         invoked with 1 parameter, 0 required.                                                    

Can you run the checks locally before pushing?

Also, there is one commit more to rebase from 2.0.x

pdureau’s picture

Title: [2.0.0-beta1] ComponentFormBuilder: make it more dynamic » [2.0.0-beta2] ComponentFormBuilder: make it more dynamic

Too late for beta1. Moved to beta2

pdureau’s picture

Priority: Normal » Major
christian.wiedemann’s picture

Status: Needs work » Needs review
christian.wiedemann’s picture

I rebased to the latest 2.0.x. Check the merge branch.

pdureau’s picture

grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Needs review » Fixed

Merged.

Thanks!

pdureau’s picture

Status: Fixed » Closed (fixed)