ComponentSourceInterface::submitConfigurationForm and validateConfigurationForm are never called

Created on 9 May 2025, 3 months ago

Overview

E.g. in the case of the block plugin, there might be code in the respective block plugins that need to be called to massage the submitted form values.

Proposed resolution

Call both these methods and have them do something

User interface changes

πŸ“Œ Task
Status

Active

Version

0.0

Component

Component sources

Created by

πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

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

Merge Requests

Comments & Activities

  • Issue created by @larowlan
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    This AFAIK ties into follow-ups opened for πŸ“Œ Add support for Blocks as Components Active that were never followed up on. A quick scan suggests:

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    This should be fixed before 1.0, but not necessarily before 🌱 Milestone 1.0.0-beta1: Start creating non-throwaway sites Active  β€” because A) ComponentSource plugins won't be a stable API yet, B) I don't see how this could impact the data storage.

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    If we're lucky, it's this simple:

    diff --git a/src/Plugin/ExperienceBuilder/ComponentSource/BlockComponent.php b/src/Plugin/ExperienceBuilder/ComponentSource/BlockComponent.php
    index f0a7b094c..8e7fa4ba4 100644
    --- a/src/Plugin/ExperienceBuilder/ComponentSource/BlockComponent.php
    +++ b/src/Plugin/ExperienceBuilder/ComponentSource/BlockComponent.php
    @@ -325,14 +325,14 @@ final class BlockComponent extends ComponentSourceBase implements ContainerFacto
        * {@inheritdoc}
        */
       public function validateConfigurationForm(array &$form, FormStateInterface $form_state): void {
    -    // @todo Implementation.
    +    $this->getBlockPlugin()->validateConfigurationForm($form, $form_state);
       }
     
       /**
        * {@inheritdoc}
        */
       public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
    -    // @todo Implementation.
    +    $this->getBlockPlugin()->submitConfigurationForm($form, $form_state);
       }
     
       /**
    
  • First commit to issue fork.
  • πŸ‡­πŸ‡ΊHungary GΓ‘bor Hojtsy Hungary

    I'm running into this in πŸ› Autocomplete machine name handling does not match to machine name Active with the webform block.

    Webform uses Drupal\Core\Entity\Element\EntityAutocomplete which has a validateEntityAutocomplete() which is where the mapping happens. That is defined as an #element_validate on the element. I tried the proposed fix in #4, that did not seem to help (change anything at all with what it did).

  • πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI

    The validateConfigurationForm / submitConfigurationForm methods in ExperienceBuilder/ComponentSource/BlockComponent aren't called at all, so the additions in #4 unfortunately won't work. This isn't a huge shock as (like the Page Data form) there isn't a traditional submit that would invoke the validate/submit methods in the way we're accustomed to.

    I attempted to submit the block form similar to how the entity form is programmatically validated/submitted in \Drupal\experience_builder\ClientDataToEntityConverter::setEntityFields and didn't have any luck - if elements in the form had #element_validate callbacks they weren't called. I suspect this is because of how complex it is to do this (a delicate balance of form state and form and input values) and not because it's an unworkable approach.

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    @bnjmnm Ah, right, this also needs ComponentInputsForm::validateForm() and ComponentInputsForm::submitForm() to call ComponentSourceInterface::(validate|submit)Form πŸ˜…

  • πŸ‡ΊπŸ‡ΈUnited States effulgentsia
  • πŸ‡¬πŸ‡§United Kingdom f.mazeikis Brighton

    Currently, as per @bnjmnm comment #7, we do not call methods proposed by @wim-leers in #4. I've tried adding suggested code as per #7, but that isn't called either.
    In fact, ComponentInputsForm::buildForm() has the following comments on L102-L106:

    // Prevent form submission while specifying values for component inputs,
    // because changes are saved via Redux instead of a traditional submit.
    // @see ui/src/components/form/inputBehaviors.tsx

    I do not think we should classify this as a bug, as we've never built form submission/validation handling mechanism. We build form to allow user to input prop values, but the only validation performed is on FE side. At least until an attempt to publish/save is made, at which point some form inputs turn out to be invalid, as they were never massaged by "submission" mechanisms.
    I suspect that this will be much more involving than just adding code proposed in #4 and #7. Specifically, adapting FE application to do submissions and validation via Drupal methods.
    Considering that current UI allows user to enter some text into autocomplete, select a value and click away - there might be some interesting challenges to figure out what constitutes "form submission" or "form requiring validation" if there are no additional UI/UX changes introduced along with this.

    And even when such changes are in, I suspect we will need thorough manual and automated testing to find potential edge cases.

  • πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    I have some thoughts, I'll push this along a bit

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
  • Merge request !1386Issue #3523496: Block form submit/validate β†’ (Open) created by larowlan
  • Pipeline finished with Failed
    10 days ago
    #560204
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Pushed up a POC but we've got a couple of open threads/questions

    * In \Drupal\experience_builder\Plugin\ExperienceBuilder\ComponentSource\BlockComponent::buildConfigurationForm we're only calling ::blockForm and we probably should be calling ::buildConfigurationForm - current code is not calling the code for blocks that override that method - e.g. \Drupal\layout_builder\Plugin\Block\InlineBlock::buildConfigurationForm
    * We have issues with #tree - BlockForm in core uses sub-form state and sets #tree => TRUE on the form. If we do don't do that we end up with a mismatch in how the form works between here and normal block forms. But if we do that, we end up with extra values in the input names - e.g. see \Drupal\system\Plugin\Block\SystemBrandingBlock::blockSubmit which expects to see block_branding in the values. We don't currently have that because we're working with the schema for the config (as seen in \Drupal\system\Plugin\Block\SystemBrandingBlock::defaultConfiguration where there is no block_branding. We also have \Drupal\experience_builder\Form\ComponentInputsForm::applyElementParents to mess with #parents.

    I suspect the way forward will be to get \Drupal\experience_builder\Plugin\ExperienceBuilder\ComponentSource\BlockComponent::buildConfigurationForm into alignment with BlockForm and use sub-form state and properly pass along settings and #tree => TRUE to the FE, then in ::clientModelToInput we can undo that in a repeatable fashion, so that we can call ::blockSubmit for blocks like SystemBrandingBlock

    The failing e2e catches these issues πŸ™Œ so that block was a good choice for test cases!

  • Pipeline finished with Failed
    10 days ago
    #560254
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    larowlan β†’ changed the visibility of the branch 3523496-componentsourceinterfacesubmitconfigurationform-and-validateconfigurationform to hidden.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    larowlan β†’ changed the visibility of the branch 1.x to hidden.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    @gΓ‘bor hojtsy any chance you could test this branch with webform to confirm it resolves the issue?
    The test module I've added has a block form with an entity autocomplete widget so 🀞 it does.

    If we're lucky, it's this simple:

    Famous last words πŸ˜‚, this one turned out to be quite the battle

Production build 0.71.5 2024