Support alternative element formats

Created on 14 September 2023, over 1 year ago

Problem/Motivation

This module currently adds custom JS code to the message structure of the webform-confirmation template and assumes that it is provided as Webform's default HTML editor markup.
But Webform can be configured to use another text format for all rich-text fields, in which case the custom code fails to get called when a webform is submitted.

Steps to reproduce

  1. Go to Webform element configuration and set the Element text format setting to something other than None.
  2. Add custom callback code to a form, using this module.
  3. Submit the form.

Expected result: The custom code is executed.
Actual result:The code is not executed.

Proposed resolution

In case said setting is active, the confirmation message is provided in a different form which this module does not expect. Since most text formats will most likely not allow <script> tags and I don't know how to allow them just for this use case, it might easier to transform the message back to Webform's default HTML editor markup before adding the tag.

Remaining tasks

Agree on solution. Commit.

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany mrshowerman Munich

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

Comments & Activities

  • Issue created by @mrshowerman
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @mrshowerman!

    I think as first step, we should add a warning in this module, if the setting you're talking about is enabled. This should be detectable from the webform's config value.

    Honestly, I'm not sure if this is solvable in a secure way at all, as the editor might just strip the JavaScript and that's not something we would revert.

    If that's the case, we need to look for other solutions, but when writing this module we already did that and didn't find a better way without needing Webform to provide support for this case and that was denied so far...

    Very happy to review patches and further ideas!

  • Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • @mrshowerman opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇩🇪Germany mrshowerman Munich

    I know that we might lose some formatting in the confirmation message if text format features are used that aren't supported in Webform's editor markup, but since we can set the text format for all elements only and not on a per-element basis, the only way is to override the format.
    I think this is acceptable in this case, because when you actively use this module, you would expect to do what it should.

    That's what the MR is trying to do.
    I agree that adding a warning to the field if a different format is selected might be helpful, so site builders aren't surprised by the format change.

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @mrshowerman looks acceptable. Still the code and comments aren't clear enough from my perspective to understand why this is needed and what it does. Could you improve that?

    Someone new into the code should be able to understand what these lines do and why they are needed. Otherwise, this might be removed one day in a refactoring, if someone thinks it's unnecessary.

  • Status changed to Needs work over 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Once finished, we also need test coverage to ensure the current functionality isn't broken (not matching the if) and the described functionality works as expected (matching the if).

  • Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • 🇩🇪Germany mrshowerman Munich

    I updated the code comment so it's hopefully clear what we're trying to do. Also added some explanation to the confirmation message help text.
    I'm working on a test as well, but that's not finished yet.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Unable to generate test groups
  • Status changed to Needs review over 1 year ago
  • 🇩🇪Germany mrshowerman Munich

    Let's see if this test passes

  • 🇩🇪Germany Anybody Porta Westfalica

    @mrshowerman thanks! Please note: 🐛 Fix failing tests and code style issues Active

  • 🇩🇪Germany mrshowerman Munich

    Yes, I saw those code style issues. Good to know there's already an issue.

  • 🇩🇪Germany mrshowerman Munich

    Added test group, but test still fails, probably due to 🐛 Tests fail because webform stable is not Drupal 10 compatible Active .

  • 🇫🇷France GuillaumeDuveau Toulouse

    Hi, it looks good however there's another case : if we use CodeMirror for the rich-text fields, there is no allowed_tags list. But maybe it's misconfiguration on my end or an issue related to webform itself.

    dpm($variables['message']);

    array:1 [▼
      "#markup" => ""
    ]
Production build 0.71.5 2024