Webform might create invalid link renderable arrays on submission list.

Created on 17 April 2024, about 1 year ago
Updated 18 April 2024, about 1 year ago

Problem/Motivation

In a draft submission, URL values in WebformLink or in Url elements might be invalid; which might break code which assume that a link element always contain valid URL object at the #url key. We discovered this issue on an environment having Menu Link Destination also installed. If there is a draft submission with invalid Url or WebformLink element, and the user visits the route of the result list, then MenuLinkDestination::preRenderLink() causes a fatal.

First we though that this is a bug in Menu Link Destination module. But the docblock of the Link render element declares that #url must be a \Drupal\Core\Url object. By using PathValidatorInterface::getUrlIfValid(), Webform tries to ensure that it only adds valid Url object to the link renderable, but it does not handle the case when the method returns FALSE.

Steps to reproduce

  1. Install Webform and Menu Link Destination
  2. Create a webform using Url or WebformLink
  3. Create a webform submission by putting a simple string 'foo' into the url/link field, and save it as a draft (which disables validation)
  4. Visit the results route of the webform.

Proposed resolution

If the Url does not validate, then pass a Url object to the #url of the link renderable array.

Remaining tasks

Satisfying the requirements of the Link render element seems to be obvious; so I don't think we need any tests coverage in this case.

User interface changes

Minor: Urls and WebformLink elements with invalid Url object are rendered on the Webform submission list (revealing the title of the link, if any).

API changes

Nothing.

Data model changes

Nothing.

πŸ› Bug report
Status

Needs review

Version

6.2

Component

Code

Created by

πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

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