Problem/Motivation
This relates to using webform in conjunction with the contributed paragraphs module, which provides a Paragraph content entity type. Paragraphs have a parent entity.
When a paragraph entity contains a webform entity reference field, it's usually desirable to use that paragraph's parent as the webform's source entity, rather than the paragraph entity itself.
There's currently no consistent way to do this.
A workaround exists for embedded forms: set set submission source entity to no). That allows the source entity to be derived from the current page. No such workaround is possible with the link to webform formatter.
Steps to reproduce
- Create a node type with a "paragraphs" field.
- Create a paragraph type that has a "webform" entity reference field.
- On the manage display settings for the paragraph type, choose link to webform for the webform field.
- Create a webform.
- Create a node, add a paragraph and populate the field in step 2 with the webform in step 4.
- View the node. The webform's source entity will be that of the paragraph, not the node.
Proposed resolution
The WebformSourceEntityManager
class has a function getMainSourceEntity
which seems to test for this: if the entity is a paragraph, use the parent. Otherwise use the entity itself.
Adapt the link to formatter in some way to use this function.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#7 | 3209462-7.patch | 1.23 KB | paulocs |
#6 | 3209462-6.patch | 766 bytes | jrockowitz |
| |||
#3 | 3209462-2.patch | 718 bytes | jrockowitz |
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedOuch!!! This is a major bug impacting 8.x-5.x and 6.x
I completely agree that the source entity for paragraphs is the main node, and this is a regression.
I am not sure if or how to apply the patch because some sites might be relying on the fact that paragraphs are mistakenly used as the source entity.
Comment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedComment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedComment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedComment #7
paulocsI tested patch #6 but the link still refers to the paragraph as source_entity.
I created a new patch and I'm using the same approach as in
WebformEntityReferenceEntityFormatter
.Comment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedIt is okay if the link refers to the paragraph. when the submission form is generated the source entity should be the node.
Comment #9
paulocsGot it! I thought the link should refers to the node.
Should I merge #6 into #7 or just re-add patch #6?
Comment #10
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedWe need to confirm if this is regression. If it is a regression we might need to provide an update hook to change any paragraph source entity to point to the main node.
Comment #11
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedHere is where I think the regression may have occurred.
#3021262: Unable to get token value [webform_submission:source-entity:?] from a paragraph field
Comment #12
paulocsI don't know how it is possible to know the right webform submission entity_type and entity_id to update them in a hook.
I did not find anything that tracked it.
Eg: how can I know which node id is the correct one for the webform submission if I have two different nodes that have a paragraph field with the webform in it.
Comment #13
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedFirst, we need to install an older version (around #3021262: Unable to get token value [webform_submission:source-entity:?] from a paragraph field) of webform and see how paragraphs were handled.
What I have done previously is check out an older release tag and gradually increment the release number.
Comment #14
paulocsOkay. I did a little a research and I think I found when the problem was introduced.
The bug start to occur after this change.
In
WebformSubmission.php
there is the methodpreCreate()
that handle the$source_entity
.See:
It is here where the source_entity and entity_id are handle.
Comment #15
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedCan you pinpoint the issue number where I introduced the regression? From there we can determine which release introduced this regression.
Comment #16
paulocsIn the issue that you pointed in #13: #3021262: Unable to get token value [webform_submission:source-entity:?] from a paragraph field
It was introduced in 8.x-5.2-beta1
Comment #17
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedI am having a very hard time understanding how paragraph source entity handling is currently set up (and I wrote the code). I am not every sure if there is a regression or just some poorly written code.
I am going to have to use the webform_test_paragraphs.module to walk through all the possible scenarios and document what is happening.
Comment #18
darvanenCame here to say two things:
Regarding 1: Would
[webform_submission:root_entity]
work for the node and leave the immediate parent available as[webform_submission:source-entity]
? Personally I think after 2 years, reversing the change would be a bigger risk.Regarding
Don't forget that sometimes people nest paragraphs.
Happy to do work on the code or more research, just need some direction.
Comment #19
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commented@Darvane I appreciate the feedback and help. I have to find the time to do an assessment of the problem (because I created it) and then I need help reviewing and resolving the problem.
I think what is happening is the source entity is changing for paragraphs based on different contexts (ie. the source entity on the field is different than when a webform is built and rendered.)
Comment #20
darvanenThat sounds like a good place to start, there's a WebfomSubmission->getSourceEntity() that is used by tokens and WebformRequest->getCurrentSourceEntity() that is called by a bunch of methods in WebformSubmission.
The former uses the WebformSourceEntityManager, the latter does not.
$source_entity is set twice, differently, within WebformSubmission->preCreate() though possibly for different purposes.
I don't see any reference to revisions anywhere in any of the three files (though a text-find may have missed it somehow).
I'm going to keep digging for a while and see if I can make heads or tails of this - as far as I'm concerned, a maintainer's responisibility is to make sure incoming code fits the design/plan and passes the requisite policies etc, not fix everything, even bugs they "created" ;)
Your guidance of course, is most welcome - for instance, should we split this issue into two? Or are these two issues so intertwined that they should be worked on together?:
- What is the source entity? The Paragraph or the eventual Node - or other entity containing Paragraphs that is loaded by the page? Can we have both?
- Why are changes to paragraph field values not flowing through to webform_submission:source-entity tokens?
Comment #21
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedI think the issue is that via the field you can decide if the paragraph or the node is the source entity but on the WebformSubmissionForm the source entity for tokens is always the node.
The patch from #6 is revealing this issue.
My concern is any fix or change is going to mess up existing installations.
Comment #22
darvanenAh... I see.
So patch #6 makes the submission form use the node instead of the paragraph for the source entity, which is what I came here to request a re-think of. This would break my "mistaken" usage of this token.
It's easily changed with enough warning but we're using a field on the paragraph to populate a handler which gives the submitting user a tag on Mailchimp that is the string set by the editor on the paragraph.
Is it possible to keep `source_entity` as the immediate parent as it has been for the past X? years and introduce a new token like `root_entity` for the use case in the OP?
Comment #23
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedComment #24
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedComment #25
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedComment #26
darvanenIn case it makes any difference, the project I was working on has removed that implementation described in #22 :)
Comment #27
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedThese paragraph issues are so tricky. I think the best we can do is develop reliable, documented workarounds, and patches.
Comment #28
darvanenSounds about right to me, it's like a hydra.
Comment #29
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedParagraphs = Hydra
might make into my next webform presentation.