Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Problem/Motivation
Steps to reproduce:
- Install OG dev version and Entityreference_prepopulate dev version. Enable Organic groups UI as well.
- Create a new content type called "Og group" and check it as group under Organic group settings
- Update Article content type and check it as "Group content" of "Og Group" content type
- Go to OG permissions overview page at admin/config/group/permissions and check "Create Article content" for members.
- Edit teh article og_group_ref field at admin/structure/types/manage/article/fields/og_group_ref and configure it to be prepopulated with URL provider
- Create a new user called member
- Create a new Og group content
- Create a new user called member and add it to the Og group content created previously
- Log in as Member user and go to node/add/article and prepopulate it with Og group id , for example : og_group_ref=1 (node/add/article?og_group_ref=1)
- Upload a image
- When we try to save the article after upload the file we get the following validation error: You must select one or more groups for this content.
Notes:
- If we try it as Super admin user , it works.
Proposed resolution
After a very very quick review: It works, if we comment the following code at entityreference_prepopulate_field_attach_form function:
if (!empty($form_state['triggering_element']['#ajax'])) {
// We are inside AJAX, so values can't be taken from URL at the
// moment, so we prevent applying any "fallback" behaviors such as redirect.
return;
}
Obviously this is not a solution.
This needs to revet #1944618: Allow getting values without validation
Comment | File | Size | Author |
---|---|---|---|
#43 | entityreference_prepopulate-ajax-prepopulation-1958800-43-D7.patch | 3.17 KB | cha0s |
#31 | entityreference_prepopulate_ajax-1958800-31.patch | 2.63 KB | heddn |
Comments
Comment #1
amitaibuRelated to #1953708: Non-members can create content in other groups - but when saved the required OG reference field is empty.
Comment #3
jastraat CreditAttribution: jastraat commentedI could be wrong, but in the new entityreference_prepopulate_get_url_or_cached_values() function, it doesn't look like the $instance variable is defined before it's used in the return value from form_state. Maybe it needs to be a parameter?
Comment #4
jastraat CreditAttribution: jastraat commentedI re-rolled this patch and the related one for OG to include $instance as a parameter and tested them. It resolves the issue with a user without create permissions adding a node to a group via the url and then the resulting node being unattached to any group.
Comment #5
jastraat CreditAttribution: jastraat commentedComment #6
amitaibuDidn't forget this issue, just not finding the time to re-code what I wanted.
Comment #7
amitaibuDid some overhaul, needs more testing.
Comment #8
amitaibuI think that this one is ready. Can anyone test?
Comment #9
amitaibuBetter title
Comment #10
betz CreditAttribution: betz commentedAmitaibu, i have OG and prepopulate running, but I don't see what is the change that should be tested.
Comment #11
amitaibuCommitted.
Comment #12
amitaibuPatch to fix OG validation.
Comment #13
amitaibuI've committed #12, as without it the OG integration is broken. No doubt tests are needed...
Comment #15
gregseb CreditAttribution: gregseb commented12: 1958800-12-og-validation.patch queued for re-testing.
oops... Clicked by accident.
Comment #17
jzornig CreditAttribution: jzornig commentedI still have the original problem that if I upload a file it breaks the prepopulate of the hidden audience field.
Comment #18
GaëlGLast dev solves the AJAX upload problem for me.
Comment #19
jlbellidoSorry but the previous comment should put the issue at "review & tested by community" or "Needs review" not in "Closed (fixed)" status.
I've tested this issue and i think that it isn't solved yet because i can reprodocuce it with OG dev version (7.x-2.7+6-dev) and Entityreference_prepopulate dev version (7.x-1.5+5-dev). For a better understanding, i add the steps for reproduce it.
thanks!
Comment #20
zdalen CreditAttribution: zdalen commentedAny progress/updates? I'm happy to help test/troubleshoot anything that's being worked on.
Comment #21
Marty2081 CreditAttribution: Marty2081 commentedThe dev version fixes an AJAX call removing the default_value for the group reference field in our case.
Comment #22
heddnRe-titling and rebooting this issue as it is still a problem. Patch that seems to resolve the issue is attached.
Comment #24
fagoRan into this as well with latest releases entityreference, og and prepulate. Turns out reading results from form state works but results get overwritten afterwards what leads to a form-rebuild with wrong information during an ajax request - attached patch fixes that.
Comment #26
heddnLet's see if this applies.
Comment #28
heddnComment #30
heddnLet's try this.
Comment #31
heddn#30 doesn't work entirely. Because it doesn't have anything in cache to retrieve. This merges in the functionality from #22, while still retaining the cache logic added in #24.
Comment #32
luismagr CreditAttribution: luismagr commentedHi!
I have applied #31 and the patch works fine for me. Really thanks for the patch :)
Comment #33
pixlkat CreditAttribution: pixlkat commentedI have applied #31 and this patch works for me as well. I am not using OG, but have a multi-value field collection which caused the same behavior after adding another item. Thanks!
Comment #34
LGLC CreditAttribution: LGLC commented#31 works for me - thanks!
I'm not using OG, but the problem occurred when an entity had both an entity reference field and a file field. The AJAX of the file field seemed to break the behaviour of entityreference_prepopulate. Previously I had to set the Action to 'Do Nothing' as a workaround, but now with the patch from #31 I can use 'Disable field' or 'Hide field' again :)
Comment #35
heddnMarking RTBC based on #32 - #34
Comment #36
zdalen CreditAttribution: zdalen commentedI'm having some trouble applying the patch. Is it possible to update the module with the change since it's been tested by a few people already?
Thanks!!
Comment #37
geek-merlinCrosslinking followup issue #2399755: Prepolulation broken when fields are attached in ajax
Comment #38
jcfiala CreditAttribution: jcfiala commentedSadly, the patch in #31 no longer applies cleanly, at least not for me.
I was able to go in and edit the changes in by hand, and they seem to be working.
Comment #39
jlbellidoHi! I've just tested #32 at the current dev version and it applies properly! :D
May be you have applied it in other module version.
Regards!
Comment #41
geek-merlinlet's verify it applies.
Comment #42
jcfiala CreditAttribution: jcfiala commentedSo, here's my weirdness. (As a side note, I'm using this with organic groups.)
I downloaded the latest dev version, and the patch applied cleanly. Fantastic!
I went in and logged in as Bob the group admin, and he was able to enter the node add form (of type photo), select an image, click on the update button, and update - and it works fine.
I log in as the site admin (user 1) and do the same thing - and I get a "The referenced group (node: 4262) is invalid." But only if I've got the field set to be hidden or disabled when the field is pre-populated. (The group nid is correct.) The problem seems to be that the group nid is being added to the default value of both the default and the (groups I'm not a part of) admin, but only after the 'update' is being pressed - if I have the field set to be disabled I can see the value showing up in the field_mode = admin section. And since 4262 is a group that I'm a member of, that group fails in the admin section. I hope that makes sense.
Basically, it's tied into if the user has the "Administer Organic groups permissions" permission - that's what makes the field appear that allows you to add this content to groups you're not a member of.
For whatever reason, not hiding or disabling the Groups Audience field seems to prevent this error, so that's how I'm side-stepping it, but I wish I didn't have to.
Comment #43
cha0s CreditAttribution: cha0s commentedThe following patch will address all issues, including those raised by #42
Comment #44
azinck CreditAttribution: azinck commented@cha0s -- thanks for the patch. Would you please provide an interdiff vs. #31?
Comment #45
cha0s CreditAttribution: cha0s commentedInterdiffs are for iterative patches. My patch is a completely different approach (save not bailing during an AJAX request), so it should be considered as entirely independent.
Comment #46
azinck CreditAttribution: azinck commentedApologies; I didn't look at it carefully.
Comment #47
cha0s CreditAttribution: cha0s commentedNo worries :)
Comment #48
ngunner CreditAttribution: ngunner commented#31 and dev release are working for me. Thanks!
Comment #49
ndf CreditAttribution: ndf commented#31 works for me too. My case is a entityreference_prepopulate with a fixed value (user-id, value should not update and not depending on ajax-request) and a ajax file-upload that triggers the issue.
#43 is a mix of new code and dropped some code for #31. @cha0s: did you do this on purpose to fix the 'needs work' #42 or should we merge it with patch #31? @jcfiala, does #43 fixes your issue?
Comment #50
ckngNot using OG, but entityreference_prepopulate with ajax form, e.g. with field_collection.
Tested #43 working for my case under 2 sites.
Comment #51
hanoiiJust tried dev with #43 it and fixed the issue with a file field whose ajax uploading was also breaking 1.5.
Comment #52
SocialNicheGuru CreditAttribution: SocialNicheGuru commenteddoes 43 also work for og? not sure given 50 and 49.
31 works for me though.
Comment #53
Alauddin CreditAttribution: Alauddin commented7.x-1.x-dev + patch from #43 tested working for me with OG
Comment #54
xlyz CreditAttribution: xlyz commented#43 works for me too. please commit.
Comment #55
bibo CreditAttribution: bibo commentedI can also confirm the patch works with latest dev - in my case for fixing image upload to an OG node.
Comment #56
antoinetooley CreditAttribution: antoinetooley commentedpatch #43 works for me with OG. Had to apply the patch manually though. Thanks!
Comment #57
milos.kroulik CreditAttribution: milos.kroulik commented#56 Can you create a new patch, based on you manual changes? Thanks
Comment #58
ZoeN CreditAttribution: ZoeN commented#43 works for me in the case of file upload fields on the same form breaking entityreference prepopulation. Thanks cha0s!
Comment #59
favosys CreditAttribution: favosys commentedThis module was working fine on a content type with just title and description but I added an image field and a file field and it stopped working. #43 did not work for me but #31 did.
Thanks a lot!
Comment #60
budalokko CreditAttribution: budalokko commented#31 and #43 both can still be applied cleanly to current dev and both worked for me on an OG context.
Comment #61
matias CreditAttribution: matias commented#43 works well for me with OG
Comment #62
Pls CreditAttribution: Pls as a volunteer commented#31 fixes the problem with file upload AJAX submit. Great job, guys. This should be commited to dev branch. Thanks ;)
Comment #63
dpw CreditAttribution: dpw commentedSo it turns out that both #31 and #43 don't work for me.I have an OG group field being prepopulated, and elsewhere on the form is the image upload, and another dropdown list field. While the patches seem to work fine for the OG group field, the "related" dropdown list field is losing its values after I click "Save" and giving the error "An illegal choice has been detected. Please contact the site administrator." The dropdown list box is using "Views Reference Filter", so a view is populating the list based on the current OG context (which is normally gets via the URL and entityreference_prepopulate). So essentially, this second list is like a dependent dropdown, only showing those nodes that belong to the group, but after you click the "upload" button, while the list of related nodes remain, once you click "Save", you get that error, and the list is now empty. I"m not exactly sure how to fix this... maybe adding the OG context in another manner, so the view can filter the list properly another way. Any suggestions?edit: So I fixed my problem by changing the validation criteria in the contextual filter of the view to be "OG group" and "Display all results for the specified field" if filter does not validate. So in this case #31 DOES work for me. I decided to leave my response text in case this helps someone else.
Comment #64
weri CreditAttribution: weri at Previon Plus AG commentedPatch #43 worked as expected for og_group_ref field but not with og_vocab. Patch #31 does prepopulate the field after an ajax operation (file-upload or item added on multiple-value-field), but gift me a validation error "The referenced group (node: 1996) is invalid".
Now i go with patch #43 and have a look why og_vocab lost the context to the url-param.
Comment #65
tyler.frankenstein CreditAttribution: tyler.frankenstein commented#43 works for me with an og_group_ref entity reference field, and another plain entity reference field both on the same content type, after uploading an image field via ajax.
Comment #66
kubrt CreditAttribution: kubrt commentedPatch #43 against 7.x-1.x-dev worked as expected for og_group_ref field. Thanks a million !
Comment #67
manuelBS CreditAttribution: manuelBS at Bright Solutions GmbH commentedConfirmed, Patch #43 works very well, thanks! I would be happy to see it in a release ;-)
Comment #69
amitaibuSorry for the late response...
I followed (the slightly missing steps) instructions of the OP and saw the error (it missed the step to allow members to create an article, and in ER-prepopulate to hide the field).
Anyway, patch looks good and working as expected. I've pushed and will create a new release.