Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
OG version: 7.x-2.0-beta1
This does not work because in entityreference_prepopulate.module (entityreference_prepopulate_og_field_default_value) line 71 there is a check for $instance['field_mode'] that fails.
There is no such item in the $instance.
If you remove this check, it seems to work.
Comments
Comment #1
amitaibu> OG version: 7.x-2.0-beta1
Please test with the --dev version of OG and ER-prepopulate
Comment #2
liquidcms CreditAttribution: liquidcms commentedi have same issue; this was working so i suspect my updating prepopulate must have broken as i have not updated OG.
can't update OG as i am not sure how... going from Organic groups 7.x-2.0-alpha3 to beta2 or -dev breaks site.
Comment #3
liquidcms CreditAttribution: liquidcms commentedyes, commenting out line mentioned above fixes this for me as well... will have to do until an upgrade path from alpha to beta rel.
Comment #4
liquidcms CreditAttribution: liquidcms commentedwas able to get og to latest -dev as well as prepopulate to latest dev.. this didn't fix.
also, now i get different widget for selecting and this widget does not have the group node listed (perhaps if it was there the prepopulate would have worked); there is also now an autocomplete field here as well; which when i type in it i get an ajax error.
Comment #5
liquidcms CreditAttribution: liquidcms commentedok, got it.
group didnt show in list since admin was not explicitly part of the group; i guess in earlier versions (alpha2) this didn't matter for admin. once i added admin as a group member; the prepopulate works (since the value i was trying to populate with was now valid).
still not sure what the autocomplete is for; but still throws ajax errors if i try to use it.
Comment #6
AndreyMaximov CreditAttribution: AndreyMaximov commentedIt's broken cause of unknown field instance['field_mode']
Quick fix
Comment #7
AndreyMaximov CreditAttribution: AndreyMaximov commentedComment #8
telematika CreditAttribution: telematika commentedSimply commenting the lines out is bad practice.
I would recommend the following code:
That works for me and the checking is still done the way the original code expects it to be.
Comment #9
skriptble CreditAttribution: skriptble commentedI'm using a clean install with all the newest version of og, entity reference, and entity reference preopopulate. No matter what I do, I can't get it to select the field automatically. I'm not quite sure what's going on.
Comment #10
ezra-g CreditAttribution: ezra-g commented#6 proposes committing commenting out code. The code should either be refactored or removed, but not commented out.
Comment #11
m.stentaAttached is a patch made against the current 7.x-1.x branch via Git, using the approach described in #8.
Comment #12
amitaibuI don't understand the patch from #11 -- what's the difference from current code?
Comment #13
m.stentaI guess the real question is: what is $instance['field_mode'] and why does that if statement return the function if it's empty (and therefore also if it isn't set)?
The patch adds a bit more differentiation to the if statement, so that if $instance['field_mode'] is not set in the first place, it will still work. But maybe that bypasses the original intention of that $instance['field_mode'] check?
What is that for?
Comment #14
telematika CreditAttribution: telematika commentedIt doesn't. ;-)
The function
empty($foo['bar']);
produces an error if$foo['bar']
does not exist. Theisset($foo['bar']);
makes sure that it exists.See isset and empty manual pages for details. The usage of
empty
is to be preferred but sometime you just needisset
.Yes, that is definitely the question. :)
Comment #15
amitaibuDo you have the widget set to "OG reference"?
Comment #16
telematika CreditAttribution: telematika commentedMy widget type is set to "Autocomplete".
If I change it to "OG reference" I get the following errors:
Comment #17
amitaibuFor OG audience to work you need to create your field with "OG reference" widget.
To get rid of those errors are probably, you probably need to re-save manually the field settings via the UI.
Comment #18
telematika CreditAttribution: telematika commentedThanks, that worked.
However if I'm a site administrator I see two widgets is that intended behaviour?
Comment #19
amitaibu> However if I'm a site administrator I see two widgets is that intended behaviour?
Yes, since you select ER field, I can't know before you set the "Selection mode" to OG, so I can't filter out other widgets.
Comment #20
amitaibu@telematika,
+ How about a doc page explaining to users about the widget + the error troubleshooting?
Comment #21
telematika CreditAttribution: telematika commentedWell, where should I put it? ;-)
Comment #22
amitaibuA patch to OG's readme maybe, or the OG's docs.
Comment #23
arosboro CreditAttribution: arosboro commented@Amitabu, "OG reference" widget isn't available in the widget selection of ERP, it's set as the widget of the field, but I have select list as the widget for ERP. Some fields work and some don't, when I disable the field and don't hide it, it shows the correct group selected, but when I save the content is orphaned. Any ideas? This only breaks when action is set to hide or disable the field.
Comment #24
arosboro CreditAttribution: arosboro commentedEntity reference does not prepopulate when using #access = false or #disabled = true. I've tested by commenting the code that sets #access to false and the reference is populated. Is there an alternative way to hide the field and still use a default value function?
Comment #25
JvE CreditAttribution: JvE commentedUpdating OG from beta4 to rc1 caused this issue to re-occur. See #1876696: Warning message in line 69 of og.field.inc using Entity reference prepopulate module.
This code :
is always wrong. The expected return-type is array and this returns NULL.
Re-saving the field settings does not fix this error.
I suspect og_update_7203 has something to do with the problem.
Edit:
Approach for a patch:
validating referenceable entities has to move from entityreference_prepopulate_get_values_from_url() to entityreference_prepopulate_get_values() so that og_context derived values are also validated.Then the whole entityreference_prepopulate_og_field_default_value() function can be removed and entityreference_prepopulate_field_default_value() can be simplified.
This would break API compatibility. (other modules calling entityreference_prepopulate functions)
Comment #26
JvE CreditAttribution: JvE commentedA rather more simple patch attached.
I still do not know what the field_mode does.
Comment #27
amitaibuAs stated in #1876696: Warning message in line 69 of og.field.inc using Entity reference prepopulate module I can't reproduce, with latest -dev. I'll need exact steps/ db dump to reproduce.
Comment #28
JvE CreditAttribution: JvE commentedYes, the problem persists with the latest dev version.
When I create content with a group audience the function entityreference_prepopulate_og_field_default_value() is called three times.
The first time $instance has no 'field_mode', the second time it is 'default' and the third time 'admin'.
When there is no 'field_mode' the function returns NULL which causes a problem in og_field_widget_form() [og/includes/og.field.inc:69] which tries to do a foreach on it.
The first time this is the stacktrace:
The second and third time it looks like this:
The og config, content types, etc are all in a Feature I cannot share yet. I'll have time to try reproduction on a clean install after the weekend.
Comment #29
amitaibu> Yes, the problem persists with the latest dev version.
You downloaded the dev version of OG? I've committed 2 days ago a fix for the notice on OG:
* e7bc86d - (HEAD, origin/7.x-2.x, 7.x-2.x) Prevent notice on node creation in og_field_widget_form(). (2 days ago)
Comment #30
JvE CreditAttribution: JvE commentedNo, OG is not at fault here and should not be changed to hide bugs in other modules like this one.
My apologies if my statements come across as blunt or offensive, my intentions are not to criticize you or your modules or to be a know-it-all. I just want software to be the best it can be.
Comment #31
amitaibu> my intentions are not to criticize you or your modules or to be a know-it-all. I just want software to be the best it can be.
Ok, but the patch is wrong:
This needs to be kept, otherwise you hit the DB for no reason.
> No, OG is not at fault here and should not be changed to hide bugs in other modules like this one.
Again, not sure about which bug you talk in ER-prepopulate - there was a bug in OG that was fixed in -dev. If I'm missing the point, please provide ways to reproduce or db dump.
Comment #32
amitaibuOk, I read you comment in #1876696: Warning message in line 69 of og.field.inc using Entity reference prepopulate module, then it seems the fix should be
Comment #33
amitaibuI've committed the code from #32. If you still see a problem, please re-open. (EDIT: I've also reverted the wrong fix from OG).
Comment #35
BrightBoldI seem to be having the same problem as @arosboro, but only on one content type. This is on a site that was upgraded from 7.1, so each content type has its own group reference field (og_node1, og_node2, etc. instead of all using og_group_ref). Three of my group content types can be used consistently to create group content with the appropriate context. On the fourth (og_node2), the prepopulate only seems to work when I have it set not to hide the field.
I am using OG rc3 and ERP 7.x-1.2 (both released well after the patches above were committed) and have my field widget set to OG Reference. All settings are identical to the ones on the three working content types. I've tried every combination I can think of of editing and resaving the field and the field widget, but it only seems to work when I turn off the "hide field" ERP setting. I'm completely stumped. For now I'm going to leave it on "do nothing" and hide the field with CSS. Any ideas what's going on here?
Comment #36
BrightBoldHmm. I just found this issue #1502972: Issues with ajax file upload fields and wonder if it may explain what's going on with my site, because the difference between the content type that doesn't work and the ones that do is that the non-working one has a file upload field. For anyone else experiencing this problem, take a look at that issue. I'll re-close this if I determine that's the problem.
Comment #37
mrfelton CreditAttribution: mrfelton commentedI also find that this does not work if the hide field option is used.
Comment #38
inno81 CreditAttribution: inno81 commentedI have exactly the same issue as #35 and #37.
Disabling "hide field" as a workaround...
Comment #39
donquixote CreditAttribution: donquixote commentedFunny explanation:
- Edit the widget type of the og_group_ref field, set it to "select list".
-> field mode is gone, prepopulate stops working
- Switch the "Entity selection" mode for the og_group_ref to "Simple", Save, then switch back to "Organic groups".
-> field mode is restored, prepopulate works again!
So it seems to be a matter of in which order you save the field configuration forms.
Comment #40
Angry Dan CreditAttribution: Angry Dan commentedI see no reason why I should have to use the OG reference widget with an OG audience field - OG doesn't require it and it won't have any effect on the field storage which widget you use.
Using latest release, if I change the widget then this module breaks.
My solution is different to the one committed above:
Simply react only when you are using the og_complex widget.
Comment #41
Angry Dan CreditAttribution: Angry Dan commentedDon't use that last patch!