Custom Webform Element Can't Render Newly Created Webforms

Created on 18 February 2025, 4 months ago

Problem/Motivation

Site Studio component configs cache available webform options at save time when utilizing either the API endpoint or the function name in select field, referenced in the README of this module. When new webforms are created, they are returned from the Webform Options List Controller, however, selecting any of the new webforms cause PHP errors AssertionError: Cannot load the "webform" entity with NULL ID. This happens because the component config isn't aware of these new webform options.

Re-saving the select field in the component fixes this temporarily, however, it's impractical for teams using config management across environments. Config conflicts and unintentional overwrites are inevitable.

Steps to reproduce

  1. Create a Site Studio component with a custom "Webform" element in the layout canvas.
  2. Add a select field to the component's form builder section.
  3. Set the select field to use either "External data source" or "Options from a custom function."
  4. Configure using provided README values for the option you choose.
  5. Save the select field.
  6. Copy the select field token into the custom Webform element.
  7. Save and close the component.
  8. Create a new webform (any structure).
  9. On a node with Layout Canvas, use your component and select the newly created webform (you may have to clear drupal cache to see the newest webform in the list of options).
  10. View the node - you'll see "The website encountered an unexpected error" with the PHP error in logs.

Proposed resolution

A few possible solutions:

  • Implement error handling to display a helpful message when webform ID is NULL, with logs indicating the problem and solution.
  • When creating new webforms, programmatically update all component configs that use the Webform element.
  • Prevent or disable newly created webforms in WebformOptionListController.php responses until component configs are updated.
πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cgrouge

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

Comments & Activities

Production build 0.71.5 2024