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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amitaibu’s picture

+++ b/og_ui/og_ui.admin.incundefined
@@ -163,6 +163,16 @@ function og_ui_add_users($form, &$form_state, $group_type, $gid) {
   $field_names = og_get_group_audience_fields();

How about moving this check to og_get_group_audience_fields().

Angry Dan’s picture

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

Status: Needs review » Needs work

The last submitted patch, member-add-field-exception-1966748-2.patch, failed testing.

Angry Dan’s picture

Status: Needs work » Needs review
FileSize
1.75 KB

Woops! Fixing that last, broken, patch - this one works - I've tested it.

Status: Needs review » Needs work

The last submitted patch, member-add-field-exception-1966748-4.patch, failed testing.

amitaibu’s picture

Status: Needs work » Needs review
amitaibu’s picture

+++ b/og.moduleundefined
@@ -2254,11 +2254,13 @@ function og_is_group_audience_field($field_name) {
+ *  Filter list to only include fields of a specific group type.

Missing space.

+++ b/og.moduleundefined
@@ -2270,6 +2272,11 @@ function og_get_group_audience_fields($entity_type = 'user', $bundle_name = 'use
+    $field_info = field_info_field_by_id($instance['field_id']);

use field_info_field()

Status: Needs review » Needs work

The last submitted patch, member-add-field-exception-1966748-4.patch, failed testing.

Angry Dan’s picture

OK, 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?

Angry Dan’s picture

Status: Needs work » Needs review
amitaibu’s picture

+++ b/og.moduleundefined
@@ -2277,6 +2279,11 @@ function og_get_group_audience_fields($entity_type = 'user', $bundle_name = 'use
+    ¶

Minor: 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.

Angry Dan’s picture

Sorry, I'm not sure I understand - which spaces should be removed?

amitaibu’s picture

Use Dreditor to see you patch

Angry Dan’s picture

Amazing! Why doesn't d.o do that stuff by default.

See new attached patch, with white space removed.

Angry Dan’s picture

This patch has a small bug, the cache isn't scoped to the entity type. Attached patch should fix that.

amitaibu’s picture

Status: Needs review » Fixed

Committed, thanks.

Status: Fixed » Closed (fixed)

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