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.

Issue fork webform_ct-3387290

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mrshowerman created an issue. See original summary.

anybody’s picture

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!

mrshowerman’s picture

Assigned: mrshowerman » Unassigned
Status: Active » Needs review

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.

anybody’s picture

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.

anybody’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

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).

mrshowerman’s picture

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.

mrshowerman’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Let's see if this test passes

anybody’s picture

@mrshowerman thanks! Please note: #3389136: Fix failing tests and code style issues

mrshowerman’s picture

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

mrshowerman’s picture

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

guillaumeduveau’s picture

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" => ""
]