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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amitaibu’s picture

Status: Needs review » Needs work

The last submitted patch, 1958800-er-og-create-1.patch, failed testing.

jastraat’s picture

I 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?

jastraat’s picture

FileSize
5.54 KB

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

jastraat’s picture

Status: Needs work » Needs review
amitaibu’s picture

Didn't forget this issue, just not finding the time to re-code what I wanted.

amitaibu’s picture

FileSize
11.27 KB

Did some overhaul, needs more testing.

amitaibu’s picture

I think that this one is ready. Can anyone test?

amitaibu’s picture

Title: Better integration for OG's "create" permissions » Module cleanup and better integration for OG's "create" permissions

Better title

betz’s picture

Amitaibu, i have OG and prepopulate running, but I don't see what is the change that should be tested.

amitaibu’s picture

Status: Needs review » Fixed

Committed.

amitaibu’s picture

Status: Fixed » Needs review
FileSize
2.06 KB

Patch to fix OG validation.

amitaibu’s picture

Status: Needs review » Fixed

I've committed #12, as without it the OG integration is broken. No doubt tests are needed...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

gregseb’s picture

Status: Closed (fixed) » Needs review

12: 1958800-12-og-validation.patch queued for re-testing.
oops... Clicked by accident.

Status: Needs review » Needs work

The last submitted patch, 12: 1958800-12-og-validation.patch, failed testing.

jzornig’s picture

Issue summary: View changes

I still have the original problem that if I upload a file it breaks the prepopulate of the hidden audience field.

GaëlG’s picture

Status: Needs work » Closed (fixed)

Last dev solves the AJAX upload problem for me.

jlbellido’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs work

Sorry 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!

zdalen’s picture

Any progress/updates? I'm happy to help test/troubleshoot anything that's being worked on.

Marty2081’s picture

The dev version fixes an AJAX call removing the default_value for the group reference field in our case.

heddn’s picture

Title: Module cleanup and better integration for OG's "create" permissions » AJAX causes entityreference_prepopulate_get_values_from_url to fail
Status: Needs work » Needs review
FileSize
1.32 KB

Re-titling and rebooting this issue as it is still a problem. Patch that seems to resolve the issue is attached.

fago’s picture

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

Status: Needs review » Needs work

The last submitted patch, 24: d7_entityref_prepulate_ajax.patch, failed testing.

heddn’s picture

Status: Needs work » Needs review
FileSize
1.61 KB

Let's see if this applies.

Status: Needs review » Needs work

The last submitted patch, 26: entityreference_prepopulate_ajax-1958800-25.patch, failed testing.

heddn’s picture

Status: Needs review » Needs work

The last submitted patch, 28: entityreference_prepopulate_ajax-1958800-28.patch, failed testing.

heddn’s picture

Status: Needs work » Needs review
FileSize
1.87 KB

Let's try this.

heddn’s picture

FileSize
2.63 KB

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

luismagr’s picture

Hi!

I have applied #31 and the patch works fine for me. Really thanks for the patch :)

pixlkat’s picture

I 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!

LGLC’s picture

#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 :)

heddn’s picture

Status: Needs review » Reviewed & tested by the community

Marking RTBC based on #32 - #34

zdalen’s picture

I'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!!

geek-merlin’s picture

jcfiala’s picture

Sadly, 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.

jlbellido’s picture

Hi! 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!

geek-merlin’s picture

let's verify it applies.

jcfiala’s picture

Status: Reviewed & tested by the community » Needs work

So, 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.

cha0s’s picture

The following patch will address all issues, including those raised by #42

azinck’s picture

@cha0s -- thanks for the patch. Would you please provide an interdiff vs. #31?

cha0s’s picture

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

azinck’s picture

Apologies; I didn't look at it carefully.

cha0s’s picture

Status: Needs work » Needs review

No worries :)

ngunner’s picture

#31 and dev release are working for me. Thanks!

ndf’s picture

#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?

ckng’s picture

Not using OG, but entityreference_prepopulate with ajax form, e.g. with field_collection.
Tested #43 working for my case under 2 sites.

hanoii’s picture

Status: Needs review » Reviewed & tested by the community

Just tried dev with #43 it and fixed the issue with a file field whose ajax uploading was also breaking 1.5.

SocialNicheGuru’s picture

does 43 also work for og? not sure given 50 and 49.
31 works for me though.

Alauddin’s picture

7.x-1.x-dev + patch from #43 tested working for me with OG

xlyz’s picture

#43 works for me too. please commit.

bibo’s picture

I can also confirm the patch works with latest dev - in my case for fixing image upload to an OG node.

antoinetooley’s picture

patch #43 works for me with OG. Had to apply the patch manually though. Thanks!

milos.kroulik’s picture

#56 Can you create a new patch, based on you manual changes? Thanks

ZoeN’s picture

#43 works for me in the case of file upload fields on the same form breaking entityreference prepopulation. Thanks cha0s!

favosys’s picture

This 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!

budalokko’s picture

#31 and #43 both can still be applied cleanly to current dev and both worked for me on an OG context.

matias’s picture

#43 works well for me with OG

Pls’s picture

#31 fixes the problem with file upload AJAX submit. Great job, guys. This should be commited to dev branch. Thanks ;)

dpw’s picture

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

weri’s picture

Patch #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.

tyler.frankenstein’s picture

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

kubrt’s picture

Patch #43 against 7.x-1.x-dev worked as expected for og_group_ref field. Thanks a million !

manuelBS’s picture

Confirmed, Patch #43 works very well, thanks! I would be happy to see it in a release ;-)

  • amitaibu committed 6d89363 on 7.x-1.x authored by cha0s
    Issue #1958800 by heddn, amitaibu, cha0s, jastraat, fago: AJAX causes...
amitaibu’s picture

Status: Reviewed & tested by the community » Fixed

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

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.