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.
When on the OG UI member add form, if you have groups of more than one entity type (in my case a taxonomy and node group type exists) then the user entity has two entity reference fields (one for each) and therefore when you go to the member add form, you are given the choice of which entity reference field you wish to use.
The problem is, that if you select the wrong one you get an exception for trying to add a taxonomy term to a node reference.
The attached patch resolves the issue by filtering out fields of the wrong type.
Comments
Comment #1
amitaibuHow about moving this check to og_get_group_audience_fields().
Comment #2
Angry Dan CreditAttribution: Angry Dan commentedGood idea! Attached is a second patch that should do exactly that.
I've had to add a group_type argument to og_get_group_audience_fields() which is a well used function already, but I'm considering if group_bundle might also be useful, since an entity reference can be locked to a set of bundles.
Anyway, thoughts on the patch are welcome!
Comment #4
Angry Dan CreditAttribution: Angry Dan commentedWoops! Fixing that last, broken, patch - this one works - I've tested it.
Comment #6
amitaibu#4: member-add-field-exception-1966748-4.patch queued for re-testing.
Comment #7
amitaibuMissing space.
use field_info_field()
Comment #9
Angry Dan CreditAttribution: Angry Dan commentedOK, new patch. Includes a re-roll, sorting the coding standard and switched to using field_info_field(). Although, not sure why - when I looked field_info_field_by_id() looked to be more performant when you have an id?
Comment #10
Angry Dan CreditAttribution: Angry Dan commentedComment #11
amitaibuMinor: Can you remove the spaces?
> witched to using field_info_field()
Core is using this, so following same pattern. field_info_field() is cached as-well.
Comment #12
Angry Dan CreditAttribution: Angry Dan commentedSorry, I'm not sure I understand - which spaces should be removed?
Comment #13
amitaibuUse Dreditor to see you patch
Comment #14
Angry Dan CreditAttribution: Angry Dan commentedAmazing! Why doesn't d.o do that stuff by default.
See new attached patch, with white space removed.
Comment #15
Angry Dan CreditAttribution: Angry Dan commentedThis patch has a small bug, the cache isn't scoped to the entity type. Attached patch should fix that.
Comment #16
amitaibuCommitted, thanks.