PHP warnings thrown for optional image or date-time SDC props without examples

Created on 8 January 2025, 13 days ago

Overview

Based on the documented criteria for an SDC to be compatible with XB, a prop must provide examples only if it's required. In other words, optional props can decide to omit examples.

When examples are not provided for an optional image prop (using json-schema-definitions://experience_builder.module/image) or an optional date-time prop ({type: string, format: date-time}), the following PHP warnings are thrown:

Warning: Trying to access array offset on null in Drupal\experience_builder\Plugin\ExperienceBuilder\ComponentSource\SingleDirectoryComponent->getClientSideInfo() (line 383 of /Users/balint/Sites/xb/web/modules/experience_builder/src/Plugin/ExperienceBuilder/ComponentSource/SingleDirectoryComponent.php)

While an example is nice for authoring templates or building render arrays using SDCs, component authors may want to omit them if they're focused on how the components behave in XB. This is because XB takes the example value and uses it as default value for props when it renders a component.

Here is an example use case when this is not desired: A component that provides an optional image prop may not want to display an example image before the user decides to choose one. With an example being provided, the Twig template can't distinguish between the example (passed as default value) and the user-entered prop value in a clean way.

This has been surfaced in the following issues being worked on for landing the first example SDCs in Drupal CMS:

Proposed resolution

Adjust \Drupal\experience_builder\Plugin\ExperienceBuilder\ComponentSource\SingleDirectoryComponent::getClientSideInfo to account for potentially no examples with image and date-time props. There are @todo items specifically for image and date-time props in the code, but this simple use case can be solved in isolation from those, and it would already help a lot with those first Drupal CMS components.

🐛 Bug report
Status

Active

Version

0.0

Component

Page builder

Created by

🇳🇱Netherlands balintbrews Amsterdam, NL

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024