Source entity type and id are not populated for a View page

Created on 17 April 2024, 9 months ago
Updated 6 August 2024, 5 months ago

Problem/Motivation

Webform has a setting to enable site-wide dialog support. When it is on, a Javascript script (webform.dialog.js) will replace the source entity type and ID in a webform's link parameters.
For example, the following link parameter

?source_entity_type=ENTITY_TYPE&source_entity_id=ENTITY_ID

will be replaced with
?source_entity_type=node&source_entity_id=1

When there is a webform dialog link inside of the node 1 page.

This functionality is working fine with node page. But it doesn't work with a View page.

After debugging the code, I think the problem comes from the following line in /Drupal/webform/RouteParametersWebformSourceEntity

https://git.drupalcode.org/project/webform/-/blob/6.2.x/src/Plugin/Webfo...

The parameters returned from Drupal routeMatch from a view route is something like

[[display_id] => page_1, [view_id] => frontpage]

In which doesn't have an entity object, but strings. Therefore, the getSourceEntity() function for a view page will return NULL as the result.

Steps to reproduce

  1. Create a webform.
  2. Create a View page.
  3. Create a block in which the block content is
    <p>
          <a class="webform-dialog webform-dialog-wide button" href="/form/your-webform-id?source_entity_type=ENTITY_TYPE&source_entity_id=ENTITY_ID">this form</a> 
       </p>
       
  4. Place the block in the View page created above.

Expected result:
The link in the block inside of the View page should be:
/form/your-webform-id?source_entity_type=view&source_entity_id=view-id

Actual result
/form/your-webform-id

Proposed resolution

Load the view entity according to route match parameter as the source entity.

πŸ› Bug report
Status

Needs review

Version

6.3

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

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