Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Tokens are not replaced on the preview page. Consider this example form:
_site_name_:
'#type': fieldset
'#title': '[site:name]'
_site_name_2:
'#type': checkbox
'#title': '[site:name]'
markup:
'#type': markup
'#display_on': both
'#markup': '[site:name]'
While tokens are replaced on the form, on the preview page, '[site:name]' is displayed.
Comment | File | Size | Author |
---|---|---|---|
#23 | 2939412-23.patch | 9.97 KB | jrockowitz |
| |||
#19 | interdiff-18-19.txt | 620 bytes | bucefal91 |
#19 | 2939412-tokens-in-preview-19.patch | 7.33 KB | bucefal91 |
| |||
#18 | 2939412-18.patch | 7.32 KB | jrockowitz |
| |||
#18 | interdiff-2939412-8-18.txt | 2.52 KB | jrockowitz |
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@Ice-D Great catch. This is a major bug.
Attached is webform that replicates the issue.
Comment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThis issue impact emails and confirmations as well. The attached webform includes a preview, email, and confirmation.
Comment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedLet's see if this patch breaks any tests.
Comment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #10
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI committed the patch. Please download the latest dev release to review.
Comment #12
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThis change is causing a regression where the admin theme can't be applied when viewing a webform submission where the webform has a token value in an element.
The problem is the token replacement in \Drupal\webform\Plugin\WebformElementBase::initialize is setting the default theme before the admin theme can be applied
I am going to revert this patch.
Steps to reproduce the issue...
Comment #13
bucefal91 CreditAttribution: bucefal91 at Websolutions Agency commentedI tried to investigate on this issue but I couldn't find the side effects you're speaking about. I have done:
/admin/structure/webform/manage/contact/submission/5
in admin theme and at/webform/contact/submissions/5
in front end theme.Did I miss some extra step?
Comment #14
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI can't reproduce the issue in my dev environment. The issue happened on client's website when you went to edit a submission, I am starting to suspect the client's website is the issue. The good news is I can test the patch on their development website.
Comment #15
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedAssigning this to myself so that I test this patch on my client's site.
Comment #16
Ice-D CreditAttribution: Ice-D commentedJust wanted to say that I'm using this patch too and have had no problems so far.
Comment #17
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe issue is the token.module's field_tokens() function calls
\Drupal::service('renderer')->renderPlain($field_output);
for all field related tokens and this initializes the default site theme and sets is as the active theme. This is causing the webform submission view and edit pages to not use the admin theme and instead these pages are using the default site theme.My specific issue is related to a token called
[webform-authenticated-user:field_user_last_name]
which is used as a #default_value for a textfield element.The patch is triggering the problem because element property tokens are now being replaced when a webform is first initialized which happens very early on in a request/page's bootstrapping.
I know this is a lot to explain and I am not even sure how to write test coverage. For now, I am including an updated patch that the resets the active theme when it is being set when tokens are being replaced. The code in the patch (and interdiff) is only triggered by my above-described edge case.
Comment #18
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe attached patch use dependency injection. I hate that this is a 'trust me' patch but trust this minor tweak solve the edge case problem.
The steps to reproduce are...
[webform-authenticated-user:field_name]
as the #default_value to the 'Name' element (/admin/structure/webform/manage/contact/element/name/edit)@bucefal91 Do you understand the general problem? If you can confirm the problem and the solution maybe we can commit the patch without any more tests. Personally, I am just looking for a reasonable amount of test coverage that prevents regressions, so I am okay not having a test for this edge case.
Comment #19
bucefal91 CreditAttribution: bucefal91 at Websolutions Agency commentedYup. I tested it too and it looks OK. I executed your steps and confirm it appears in the front end theme. I also reviewed the patch and didn't find anything.
The only thing is that I replaced one more invocation of
\Drupal::service()
with the injected service. Interdiff will tell it better than my English.Comment #20
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@bucefal91 Thanks for fixing that mistake. I committed the patch.
Comment #23
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe regression in #2968554: Clear cache via the UI is throwing an exception is making want to try a safer approach.
Comment #24
andileco CreditAttribution: andileco at JSI Research & Training Institute, Inc. (JSI) commentedI applied this to 5.x-dev on my site, and I am no longer getting the "error occurred" page like I was getting before. The token replacement is working for me too.
Comment #25
andileco CreditAttribution: andileco at JSI Research & Training Institute, Inc. (JSI) commentedComment #27
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented