The entity reference field widget "OG reference" does not filter on its configured membership type.

Example:

Membership types:

  • host
  • partners

Entity types:

  • node/group
  • node/article
    • Entity reference field_group_host
    • Entity reference field_group_parents

Both fields will contain all memberships, regardless their membership types.

Files: 
CommentFileSizeAuthor
#20 1872016-og-widget-select-20.patch3.44 KBamitaibu
PASSED: [[SimpleTest]]: [MySQL] 745 pass(es).
[ View ]
#15 new.png29.07 KBcasey
#15 edit.png29.71 KBcasey
#12 og-1872016-9.patch1.35 KBcasey
PASSED: [[SimpleTest]]: [MySQL] 733 pass(es).
[ View ]
#10 og-1872016-8.patch1.35 KBcasey
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/og/includes/og.field.inc.
[ View ]
#8 og-1872016-7.patch1.33 KBcasey
FAILED: [[SimpleTest]]: [MySQL] 733 pass(es), 0 fail(s), and 4 exception(s).
[ View ]

Comments

amitaibu’s picture

Hi casey, long time!
That's indeed a bug. Are you going to work on it? :)

casey’s picture

Hi to you too, long time indeed!
Couple of questions:

  1. Shouldn't the membership_type setting be part of OgBehaviorHandler instead of OgSelectionHandler? membership type doesn't affect referenceable entities.
  2. This would also allow us to use OgBehaviorHandler::load() to load the form values, wouldn't it?
amitaibu’s picture

> "OG reference" does not filter on its configured membership type.

Re-looking at this, I might have misread it the first time.

Every og-audience field is related to a membership type. Meaning that the type of the membership that is created when a reference is made, can be changed from field to field. What is referenced from the field, can be any entity -- which you can limit via the field's UI, or have your own Entity-reference selection handler.

Is it answering your question?

casey’s picture

No I don't think you have misread it. I ve looked into it some more and only the "OG reference" widget is affected.

This is probably the case because og_field_widget_form() calls og_get_entity_groups() to retrieve its form values.

While normal entiryreference widgets use the form values provided by Entityreference (in this case through OgBehaviorHandler::load())

Still need to test it but I guess this issue is fixed by replacing (in og_field_widget_info())

<?php
    $entity_gids
= og_get_entity_groups($entity_type, $entity);
   
$entity_gids = !empty($entity_gids[$target_type]) ? $entity_gids[$target_type] : array();
?>

by

<?php
   
// Build an array of entities ID.
   
foreach ($items as $item) {
       
$entity_gids[] = $item['target_id'];
    }
?>
casey’s picture

Errr no normal widgets allow you to select any group. I guess you shoudn't use other widgets for OG fields.

casey’s picture

Still my solution seems to work

amitaibu’s picture

> Still my solution seems to work

What solution?

casey’s picture

Status:Active» Needs review
StatusFileSize
new1.33 KB
FAILED: [[SimpleTest]]: [MySQL] 733 pass(es), 0 fail(s), and 4 exception(s).
[ View ]

This one

Status:Needs review» Needs work

The last submitted patch, og-1872016-7.patch, failed testing.

casey’s picture

Status:Needs work» Needs review
StatusFileSize
new1.35 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/og/includes/og.field.inc.
[ View ]

Status:Needs review» Needs work

The last submitted patch, og-1872016-8.patch, failed testing.

casey’s picture

Status:Needs work» Needs review
StatusFileSize
new1.35 KB
PASSED: [[SimpleTest]]: [MySQL] 733 pass(es).
[ View ]

Arr

amitaibu’s picture

Sorry. can you attach a screenshot of the problem, I'm not sure I follow.

amitaibu’s picture

casey’s picture

StatusFileSize
new29.71 KB
new29.07 KB

@images
Publisher field has membership type set to "Publisher"
Co-publisher field has membership type set to "C0-publisher"

new.png contains screenshot of what I selected when I created the node.
edit.png contains screenshot of what the widget contains when I edit the node.

Both fields will contain all memberships, regardless their membership types.

@problem
Currently field widget contains all memberships with configured target type and optionaly configured target bundle.

While it should contain all memberships with configured target type and optionaly configured target bundle, and configured membership type.

og_get_entity_groups() does not allow for that.

casey’s picture

I didn't understand #1865944: Allow implementing modules to change the My/Other groups selection earlier. That one is about allowing to extend "other groups". That's a feature request while this is a bug.

amitaibu’s picture

Right, I understand the problem. How about a little test? :)

amitaibu’s picture

btw, I don't think it's related to membership types -- it's the fact that you have two audience fields on the form

amitaibu’s picture

I'll give a stab with a test.

amitaibu’s picture

StatusFileSize
new3.44 KB
PASSED: [[SimpleTest]]: [MySQL] 745 pass(es).
[ View ]

Patch with test.

amitaibu’s picture

Status:Needs review» Fixed

Committed, thanks.

Status:Fixed» Closed (fixed)

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