Problem/Motivation

I have a custom block that needs to reference the form structure in its submit handler. However, when that block is added to layout builder, it can't find any of the fields it expects in its form.

I determined this is because ConfigureBlockFormBase.php passes the entire form to the submit handler instead of just the subform.

Steps to reproduce

N/A

Proposed resolution

I'm actually a bit puzzled what the "correct" way to invoke the submission handler subforms--I see examples of both in core:
1. The submit handler only passes the subform
* Drupal\field_layout\Form\FieldLayoutEntityDisplayFormTrait
* Drupal\image\Form\ImageEffectFormBase
* Drupal\layout_builder\Form\ConfigureSectionForm
* (and more)

2. The submit handler passes the whole form
* Drupal\block\BlockForm

Based on what appears to be the intention, I think the attached patch is correct.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

Comments

mediabounds created an issue. See original summary.

mediabounds’s picture

Status: Active » Needs review
StatusFileSize
new948 bytes
mediabounds’s picture

StatusFileSize
new1.79 KB
new792 bytes

Also updating BlockForm since as I review other examples in core and contrib modules, I think the intention is to only pass the subform.

(Not sure if the component should change here)

The last submitted patch, 2: 3227026-1.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 3: 3227026-2.patch, failed testing. View results

mediabounds’s picture

Related issues: +#2948549: Sub form not passed to BlockPlugin's submit callback

The failing tests indicate this is the intended behavior…which seemed bizarre to me. So after some searching, I found that this is a known issue with Block which has essentially been replicated in Layout Builder: #2948549: Sub form not passed to BlockPlugin's submit callback

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.