Fatal: Default value for component props

Created on 29 September 2025, 25 days ago

Problem/Motivation

In UI Patterns 2, we didn't care so much about required props because it was managed by the Form API:

  1. if a prop is required, we add the #required render property
  2. ComponentForm can be submitted without filling a value
  3. So it is not possible to render a component without required props filled

In Display Builder, we can render component without subimiting ComponentForm:

  • on preview panel
  • on builder panel
  • also on final dsipaly rendering if the component was only dropped without any change in ContextualForm

So we have this fatal error:

Twig\Error\RuntimeError: An exception has been thrown during the rendering of a template The property xxx is required."

Proposed resolution

Add default values to required props.

There is 2 places where we can do this:

  • ComponentLibraryPanel: this is the best place in my himble opinion, because the logic is executed only once by buildign session and can be easily cached
  • Instance::attachToRoot and Instance::attachToSlot, so executed at each attachment

The logic, if the prop is required

  1. Set the default value if exist
  2. Set the first examples value if exist

We can go further, but it would be come complicated.

Other tasks

Do we need to add the rule in sdc_devel: "each required prop must have a default value" ?

🐛 Bug report
Status

Needs work

Version

1.0

Component

State Manager

Created by

🇫🇷France pdureau Paris

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024