[2.0.0-beta1] ComponentFormBuilder: make it more dynamic

Created on 2 May 2024, about 2 months ago
Updated 10 June 2024, 18 days ago

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

πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

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

Comments & Activities

Production build 0.69.0 2024