"During creation, when clicking "add another" on a multiple cardinality field, entities $sid internally is changed. "
Well, it's kind of hard to replicate, but.. Modules I'm using:
Entityform
Workflow 7.x-2.x-dev using 'Workflow Field'
Workflow fields 7.x-1.x-dev with some patches: #2612674: Author is not calculated properly for entities
#2148935: Make module compatible with workflows defined through "Workflow field" module
So, Let's say that I have an entityform with 2 states: "(creation)" & "New" & it's properly configured so author can make the transition (creation)-> New.
And the entityform has a simple field (let's say a text field) with unlimited cardinality (so we have the "add another" button).
Now, workflow fields is configured to allow the author to edit it during creation, but not when the workflow is set to "New".
So.. during creation, if the author clicks on the "Add another" button, suddenly the field disappears.
After some debugging, I've figured out that when the form is being created, the sid is set to "creation"'s value (as expected), but when the author presses the "add another" button, the sid returned from workflow_node_current_state is set to "New".
I know that this only causes an issue in workflow_fields, but I think that if entity hasn't been created yet (it's "is_new" variable is set to TRUE), the expected behaviour of workflow_node_current_state function is to return creation stage sid.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | workflow-wrong_sid_during_creation_add_another-2612702-17.patch | 679 bytes | zekvyrin |
Comments
Comment #2
zekvyrin commentedComment #3
zekvyrin commentedComment #4
johnv2 things with this patch:
- Please try the same on a 'normal' Add entity page.
- Your patch is above determination of the field_name. Why?
Hope to hear soon from you.
Comment #5
johnvAlso, please install very latest version.
Comment #6
johnvAnd also, can you conform to the $sid = _creation... pattern?
or doesn't it work in that case?
Comment #7
zekvyrin commentedWith your questions I did some additional digging with this.
I tried today's dev, issue still existed in my case.
Then, I tried to replicate this on a node. The issue wasn't there. That made me wonder why...
First of all, "normal" (node,users) & other entities have some differences.. is_new attribute doesn't exist in $form['#entity'] variable
on node/add page, although it does appear in entityform submission creation page.
After some additional digging, I found out why this is happening:
The '$entity' variable doesn't contain the workflow field when
- creating a node
- trying to add another item (during node's creation)
- creating a new
But (during Entityform Submission's creation) when trying to add another item, the '$entity' variable contains the workflow field and had the "New" state's sid, so line 695 (current dev version) returns a value in $sid.
Indeed there is no reason for it to be above field_name determination, although because it already existed (field_name was given as argument), I didn't notice it earlier. So with this patch I've uploaded (it's just a temporal fix) I'm just actually moving field_name after re-setting it. Although instead of forcing it there to return a value, we could also alter the final if when there isn't any current state.
But maybe some additional debugging is required before applying it.
I can try and test it in another entity if you want (planning to do it when I have some more time). Maybe instead of force-setting it there (where is_new), it would be better to not have a value in entity variable at first place (if that can be changed), so maybe some additional digging is required. But I would need some help probably to find where it does that and if we can change it.
On the other hand the reasoning "If the entity hasn't be saved yet, force (creation) sid" seems pretty valid to me as well.
Comment #8
zekvyrin commentedSorry forgot to add the patch in previous comment
Comment #9
zekvyrin commentedAlso uploading an alternative patch: added the condition when entity is new in the final if-clause.
Comment #10
zekvyrin commentedDamn :/ Ignore #9 (it's actually the same as before), this is the alternative.
Comment #11
johnv:-)
FYI, one hour ago, I fixed this: #2613204: WSOD when adding/editing a non-node entity with workflow_field
It is also about non-node entities. Please use latest dev version of tomorrow.
Comment #12
johnvPatch #10 doesn't change the logic, does it?
What is the result of this code:
Comment #13
johnvI guess the same happens when you have a normal node, and press the Preview button.
Comment #14
johnvIMO you can use this in your code:
if ((!$sid) || (!empty($entity->is_new) )) {For the preview mode:
if ( !$sid || !empty($entity->is_new) || !empty($entity->in_preview) ) {I guess we do not need creation_state, but workflow_node_previous_state
Comment #15
zekvyrin commented#11) Ok, will do tomorrow
#12) No, not changing anything results exactly the same every time. I just added it to conform (like you said in #6).
#13) Also, will try to test it tomorrow
#14) I guess you're right about the code. I haven't met a situation when "is_new" is set, but is false (and I don't think there should be).
But why "previous"? This only happens in creation (for me). I have also test it in other states (e.g. when on "new") and the problem doesn't exist there (ok not with using node's "preview")
Comment #16
johnvIn your case, previous and creation is the same, but not in preview.
Comment #17
zekvyrin commentedHello john,
I tested everything today with latest dev.
Yes issue still exists on that dev, and also you were right about node preview.
I made a new patch using workflow_node_previous_state and including $entity->in_preview in the if clause, as you said in #14.
Comment #18
zekvyrin commentedComment #19
johnvComment #20
johnvFixed in 2.6+dev
Comment #21
johnvNeeds changes in D8, too.
Comment #22
johnvThi sis done in 8.x-1.0-beta1+dev.
Back to lowest version.
(apparently, d.o. updates for commits are behind.)
Comment #24
johnv