Exception handling in FieldBlock.php breaks AJAX forms provided via formatter

Created on 5 July 2024, 2 months ago
Updated 17 July 2024, about 2 months ago

Problem/Motivation

Hello, The FieldBlock.php block plugin (field_block) from layout_builder, which is used to display entity fields, does not throw a FormAjaxException, so AJAX forms provided from field formatters are not submitted.

Steps to reproduce

Create a formatter that provides an AJAX form, try to submit it, you will get the error: The field "field_name" failed to render with the error of "".

It is also necessary that in the entity_view_display configuration, this field should not be in the content section, since LayoutBuilderEntityViewDisplay::buildMultiple calls the parent EntityViewDisplay::buildMultiple, which duplicates the formatter view call, thereby skipping exceptions before it gets to FieldBlock.php.

Proposed resolution

Throw a FormAjaxException exception in the same way as you would with an EnforcedResponseException exception.

Remaining tasks

  1. Test coverage.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

-

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
Layout builderΒ  β†’

Last updated 1 minute ago

Created by

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @kay64
  • Issue was unassigned.
  • Status changed to Needs work 2 months ago
  • Pipeline finished with Success
    2 months ago
    Total: 494s
    #217005
  • I made the error message more descriptive using "Error::logException()". This will be useful because some exceptions do not have a message (as in the case of "FormAjaxException") and their cause is implied in the name of the exception class.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 447s
    #226280
  • Pipeline finished with Failed
    about 2 months ago
    #231905
  • Pipeline finished with Failed
    about 2 months ago
    Total: 463s
    #231922
  • Pipeline finished with Failed
    about 2 months ago
    Total: 457s
    #231940
  • Pipeline finished with Failed
    about 2 months ago
    Total: 169s
    #233372
  • Pipeline finished with Success
    about 2 months ago
    Total: 1447s
    #233385
  • Pipeline finished with Success
    about 2 months ago
    Total: 622s
    #233414
Production build 0.71.5 2024