Components with optional images BadRequestHttpException

Created on 15 April 2025, 7 days ago

Overview

It is possible this extends beyond the optional images mentioned in the issue title, but this is where I'm running into it.

To reproduce:

  1. Enable the xb_test_sdc test module
  2. Add the XB test SDC with optional image and heading component to the layout
  3. Make an edit to the heading prop. This should be the first edit made to this component, leave the image prop alone
  4. The PATCH request will fail with a BadRequestHttpException

The exception is thrown from here

 $prop_source_array = $client_model[$sdc_prop_name] ?? NULL;
      if ($prop_source_array === NULL) {
        // The client didn't send this prop but should. This is an error OR the
        // data has been tampered with.
        throw HttpException::fromStatusCode(Response::HTTP_BAD_REQUEST);
      }

And it looks like image is not present in the $client_model sent to it
as it isn't included in the value ofGeneratedFieldExplicitInputUxComponentSourceBase::clientModelToInput if the field hasn't been edited yet.

Speculation...
At first glance, it seems like clientModelToInput() is running into this because it's looking for an explicitly set 'default_value' when no value is set, and when that doesn't exist (such as the yet-to-be-edited optional image), it fails the try block and isn't added to the resulting array.

Proposed resolution

More Speculation...

  • Fall back to examples if a default value doesn't exist?
  • Require default values like we do examples?
  • Update the logic in clientModelToInput() to handle empty values differently?

User interface changes

🐛 Bug report
Status

Active

Version

0.0

Component

Page builder

Created by

🇺🇸United States bnjmnm Ann Arbor, MI

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

Comments & Activities

Production build 0.71.5 2024