Here's the issue. User-A creates a node and sets the Audience to Public and to several groups. The node shows up on the front page as intended, but now when User-B clicks on the node they are taken arbitrarily to one of User-A's groups. This seems confusing from User-B's perspective. Is there currently a way to keep the node public, yet prevent User-B from being taken to a group?

Comments

moshe weitzman’s picture

there is some code there that tries to do the mnost sensible thing. what would be your rules here? we could show the group in the context of several nodes here. please see the $_SESSION['og_last'] code to understand what we do here.

jcruz’s picture

Thanks for the reply. Could the $_SESSION['og_last'] code be wrapped in 'if (og_is_group_type($node->type){' so that the group context is only set if the prior page view was a group? That way if a public node is viewed off the front page there is no group context.

moshe weitzman’s picture

i'm not too fond of that logic. there are plenty of valid reasons to se two nodes in a row, or see a node frm the subscribers page, or any other group page.

jcruz’s picture

I see your point. What would be nice though would be a way to distinguish 'group pages' versus clearly 'non-group pages' such as the frontpage or search results. I'll play around with the code some and see what I can come up with.

moshe weitzman’s picture

we already have that. it is called group_context. if a page is a group page, then og_get_grou_context() returns a group node.

Anonymous’s picture

I don't think it is bad behaviour that a user can see that a node belongs to a specific group, but what does puzzle me about the scenario outlined above is that user A can not be sure which group user B is taken to.

Example: I publish content to one of my groups, but think it could also be interesting to other groups I am a member of. This could then lead to the node being shown in one of the other groups - annoying in a case where I want to make it obvious where the content originated from.

moshe weitzman’s picture

Status: Active » Closed (fixed)

In order to get rid of that ambiguity we need to ask the user which of his groups is the primary group and i don't think thats very sensible from a ui perspective for most sites.

Anonymous’s picture

Status: Closed (fixed) » Active

I can see your point, but then I do have the opposite problem with my users. I often get complains because people say their content should be marked as belonging to the group they posted it to and not to some other group. The node, of course, belongs to several groups, but themes, the group details block etc. only relate to one group. And this constantly annoys my users because they do not understand it. And it can even be hard for the admin if themes and groups are connected.

Would it be possible to have an option to enable a primary group setting? Then people like me and jcruz would be happy and your users would not be bugged by a cluttered interface...

moshe weitzman’s picture

Title: One node, many groups » Specify a primary group which determine group context when node is in multiple groups.
Category: support » feature

If someone makes a clean patch with a reasonable UI, I will likely commit it ... This might be doable as a helper module. An analogous module for taxonomy is primary_term

Anonymous’s picture

Okay, we will look into this!

moshe weitzman’s picture

Consider the scenario where a primary group has been specified, aliong with 3 other groups. Then an email notification goes and a different user clicks the link. This user got the notification because she belongs to one of the 'other' groups, not the primary group. In what group context should she see the msg? The primary group, or the one she belongs to?

Anonymous’s picture

I think this will depend on the context of the respective website. For our site, it would be important to make sure where the content originated from, so I would choose that options. For others it may be that they think it should be the group the user is subscribed to - but that approach also has problems: what happens if you are subscribed to all the groups a node belongs to, just not the primary group?

So, after thinking about this I would say primary groups should be made an option; and those who chose it will then also set in which context the node is displayed. This also helps where group association of nodes controls the themes - in that case it would be crucial to set which group a node belongs to.

KingMoore’s picture

any progress made on this? I am interested.

moshe weitzman’s picture

Version: 5.x-3.1 » master

Nope - still awaiting a patch. Patch must be against HEAD/D6

KingMoore’s picture

Thanks. Do you have thoughts on what implementation path a patch should take?

Anonymous’s picture

We had to change the way groups are set up on our system which made other development work more important than looking into this. I still think it would be a useful feature to add but I doubt that we will be able to commit development time within the next few months - though happy to take part in discussions and testing until we have resources available.

KingMoore’s picture

TfR75,

I may have some time to work on a patch here. Not sure.

Do you have any thoughts on how this should be implemented? Simply a checkbox next to the available groups to allow a user to select a primary group? A weighting to allow for ranking of group priority? Plus a setting to turn this on or off? Other ideas?

As a bit of background, the reason I want this functionality is pretty simple. I am building a site with a breadcrumb, and I want to be able to control which group shows up in the breadcrumb for content items if the item is assigned to multiple groups. The only functionality I would look to provide would be that which lets a user select the primary group(s) for a node. Then I would provide a function that returns the primary group of a node. I would leave any further integration/development to others.

Anonymous’s picture

Kingmoore, I would vote for the simple check box. A weighting, I think, would only make sense if there was a clear scenario in which it would add real benefit. For breadcrumbs etc. you would only want one group to be displayed. More functionality, such as a weighting, is always nice, but I agree with Moshe's previous comment that the UI should be kept as simple as possible. Which is why I also think that the admin should have the choice on whether to activate the feature at all. If you don't need it it will only confuse users.

So my preference would be a check box (or perhaps a drop down field to ensure that there really is just one primary group) together with a setting for the admin to turn it on/off.

KingMoore’s picture

TfR75,

That sounds good. Just to clarify:

- Admin could turn primary group selection on/off
- Users could specify exactly one primary group
- Primary group could be returned via an api function

KingMoore’s picture

couple questions:

- how should this act if no primary group is selected? take the first (random) group and set it as primary? save no primary group? if the latter, should the api function to return a node's primary group return null? or should it return the first (random) group?

- suggestions on where to store the primary flag in the db? (is_primary tinyint(4) DEFAULT 0 NOT NULL on og_ancestry table?)

KingMoore’s picture

Status: Active » Needs review
StatusFileSize
new5.32 KB

Here is an initial patch. Very simple:

- adds og_primary field to {og_ancestry} (tinyint, default 0, not null)
- implements admin setting to turn on/off primary groups. defaults to off. (wording is audience to be consistent, but I think this is confusing!).
- provides a select box of groups to select as primary audience under the audience check boxes and saves to {og_ancestry}
- persists primary group if in simple mode
- provides api function og_get_primary_group which takes a node and returns its primary group node if one exists

Trying to keep this simple as things could get complicated quickly if we try to do too much here. Comments? Thoughts? Questions?

KingMoore’s picture

Has anyone successfully applied this patch? Feedback would be great.

Anonymous’s picture

This may be too late to be of use but here are my thoughts, just in case:

Currently, OG seems to pick a group (I am not sure how it does that, maybe based on creation time of the group) and display the node in the context of that group. If an admin wanted to activate primary groups for their site then the module could just use this group as a primary group. So in a way that would be the functionality as it currently stands but it would allow admin and/or user to change the primary group if they felt it was important.

Anonymous’s picture

Thanks very much for the patch! Unfortunately, I cannot test it at the moment as we are still running Drupal 5 and I do currently not have a test system.

KingMoore’s picture

TfR75: I believe Drupal just chooses the group that gets fetched from the database first in the situation you are talking about. In reality, that isn't always the one you want to display for any given node.

Or do you mean when turning on the Primary Groups option on an existing site, rather than returning no primary group (NULL) for nodes where a primary group has not been selected, the API function should return the one that gets chosen [somewhat] randomly by Drupal?

Anonymous’s picture

Currently, OG does actually do something like a primary group, by, as you say, picking one group as the group in which context the node will be displayed. What I meant to suggest was that when the new Primary Group feature is introduced to an existing site this group could become the primary group if it was necessary to define one for every node - taking this approach would not actually make any (visible) change to the system as the node would still be displayed in the context of the group it was in before. But it would allow users who are not happy about the group to change that. New nodes would only get a primary group if one was assigned to them.

Another way of doing it would be not to have a group as the primary one when the new feature will be introduced to an existing site. The disadvantage could be that with large sites admins/users would then have to designate a primary group for each node.

Maybe administrators could choose one of the two option when they introduce Primary Groups to an existing site?

KingMoore’s picture

This would not be too difficult to do. I would just need to change the API function to return current($node->og_groups) instead of NULL if a node has been assigned to groups but no primary has been set. Anyone else have an opinion on this?

Also, I see that in the code it refers to this group as the 'active' group in some comments. Should I update the patch to call this functionality selecting the 'active group' instead of 'primary group'? What makes more sense?

KingMoore’s picture

One other thing, I see this in the code:

/**
 * Set group context based on URL. Modules may override what we set here.
 * Set a custom theme based on what group is being displayed (if any).
 * Be smart about selecting the 'active' group for ambiguous urls like node/$nid
 * TODOL see http://api.drupal.org/api/function/menu_get_object/6
 */
function og_determine_context() {

It says 'Modules may override what we set here'. Does anyone know how? Or have a better idea what the author meant?

moshe weitzman’s picture

That mean, "modules may call og_set_group_context() whever they need to."

moshe weitzman’s picture

I'd love some patch reviews and collaboration here. Still a worthwhile feature.

moshe weitzman’s picture

The group thats chosen for context when someone views a cross-posted node is highly dependant on who you are and what your last page view was. There is no point in trying to maintain old behavior in this patch. Nodes created before this code exists should just have no primary group.

moshe weitzman’s picture

Status: Needs review » Needs work
StatusFileSize
new5.71 KB

This looks like a good start. Here is a reroll, with some better language and minor fixes. Some outstanding issues an dcomments.

  1. I think 'primary group' is the right terminology.
  2. I don't see the primary group being used to set context for the page. i think that should be used if available, otherwise fall back to current logic. eventually, we might toss out current logic but i think we should keep it for now.
  3. If only 1 group is chosen, should that group automatically be marked as primary? if so, the default value of primary form item should also come from $_GET['gids']. Furthermore, what to do when there is a discrepency between primary audience and audience? we handle situations like this elsewhere on this form using some smart javascript.
  4. i want the primary group to be available in the $node object. That means it should be loaded during og_nodeapi(load). Thats what should be consulted in og_get_primary_group(), not the DB directly.

is anyone available to work on this? It is pretty close.

gmclelland’s picture

StatusFileSize
new14.66 KB

You should look at b2evolution. Here is a link to their demo site.

It is a multiblog engine that allows cross posting to different blogs.

View the attachment to see how they specify a primary group with radio buttons and additional groups with checkboxes.

Food for thought.

Hope that helps,
-Glenn

csc4’s picture

Subscribe

lloydpearsoniv’s picture

subscribe

cwaring’s picture

I'm very interested to see this functionality implemented, mostly to help facilitate cross-posting support in the spaces_og module.

kevinwalsh’s picture

subscribing

that0n3guy’s picture

subscribing, I'm all about this for spaces_og...

Grayside’s picture

Priority: Normal » Major
Issue tags: +spaces_og, +multigroup
Grayside’s picture

Version: master » 7.x-2.x-dev

7.x first for concept/architecture discussion.

amitaibu’s picture

This sounds custom, and I think it can be solved easily outside of OG core:

1) Attach a checkbox field to a group, to indicate if it's primary.
2) When viewing a group contnet, iterate over the groups, and find the first one with the primary, and og_conetxt() that group.

jgraham’s picture

What about adding a sort to the cached object returned via og_get_entity_groups() or in og_context_determine_context()?

og_context_determine_context() currently returns the first entity. Right now it's arbitrary as to how the result set, primarily from og_get_entity_groups(), gets ordered and is likely dependent on whatever storage system is returning the result set.

The other option would be to add a hook entry point into og_get_entity_groups() or og_context_determine_context() so that it can easily be delegated what logic should determine the primary group by sorting the $gids array when multiple potential contexts are possible.

Grayside’s picture

While this may sound custom, the concept of greater control around a primary group association has been a recurring theme around many OG IA discussions I've been part of. The lack of increased clarity or more complete separation is why systems like Spaces simply cut out multigroup, and why some OG-driven systems replace multi-group with a content syndication/duplication system.

For that reason, even if OG Core does not address this, I think there needs to be a single, general-purpose solution that is the focus of the Primary Group concept. Perhaps it is in http://drupal.org/project/og_primary?

amitaibu’s picture

While this may sound custom, the concept of greater control around a primary group association has been a recurring theme around many OG IA discussions I've been part of

You are right, I can see the issue is going a few years back. But still I think it can be in contrib.

og_context_determine_context() currently returns the first entity. Right now it's arbitrary as to how the result set, primarily from

That's even a better suggestion than mine. Instead of calling og_context(), the "Primary Group" module can implement an og-context handler.

Grayside’s picture

So for a D6 version, there's a couple ways to go. First, some kind of logic/alter hook/etc in og_context_determine_context(). Other possibility: The current -dev includes code that preempts og_context_determine_context() from running if a context is already set. This is a performance enhancement for sites using OG & Spaces, or similar systems that try to determine the context before og_init() is even fired.

This means a lower weight OG Primary module could have it's own logic--og_primary_determine_context().

liquidcms’s picture

ughh!! really not liking the D7 upgrade of d.org!!.. let's try this again...

wondering if any update/progress on this issue?

pretty sure this is the same use case i have; but just to be sure:

i need:
- primary og field (single, required, used to determine context and access control)
- secondary og field (multiple, not required, used to determine access, NOT used to determine context)

before i saw this thread i figured best approach was to modify og core to simply add a checkbox to the og field: "use in og context"; but then after reading through this i think possibly just a hook to allow contrib modules to alter might be more flexible. first approach however is certainly easiest ui for site devs.

as far as i can see there is no hook in to og_context_determine_context() for a contrib module to alter the result set. likely the best place to start.

liquidcms’s picture

Issue summary: View changes
StatusFileSize
new632 bytes

I am guessing there is another solution for this but i haven't stumbled upon it yet.. so this patch was the simplest solution i could think of.. it simply adds a hook to allow altering the contexts returned in og_context_determine_context(). With that, and the set up i described above, i utilized this hook in a custom module like this:

function MYMODULE_og_context_determine_context_alter(&$data) {
  if (!is_array($data['node'])) return;
  $ids = array_keys($data['node']);  
  $results = db_query('SELECT id, gid FROM {og_membership} WHERE id IN (:ids) AND field_name = \'og_group_ref\'', array(':ids' => $ids));
  $valid = array();
  foreach ($results as $result) {
    $valid['node'][$result->id] = $result->gid;
  }
  // if we dont have any valid gids, i.e. the PRI was not set.. it is likely a node set up issue; but lets just return full result set in case it has values
  if (count($valid)) $data = $valid;
}

basically i discard any og membership records that are not from my primary og field

i also realized that og won't allow me to include the same group in 2 fields (it silently just discards the value and i end up with errors downstream). so i also added a form validation call to ensure my primary group was not in the secondary group.

mccrodp’s picture

This issue is quite old. I'm just wondering what the latest recommendation for selecting a primary group per group content instance is now.

  1. Should this issue remain open awaiting a possible patch to OG core?
  2. Is this something that should exist in a contrib module, or does it already somewhere?

My current solution with minimal code is to use a combination of suggestions in posts above from @Amitaibu and @jgraham.

  • Use autocomplete widget, as it is draggable, for og_group_ref field and use group at index 0 as primary group (otherwise use checkbox with custom code)
  • Call og_context_determine_context() to return primary group when setting og_context

EDIT: re-ordering of groups using the autocomplete provided by the OG Reference field widget does not work: #2335969: OG Reference widget autocomplete does not save the reordering of groups. The work around is to ensure that the primary group was the first to be added to the Audience Field. If not, the references need to be deleted and re-added in the desired order it seems.

joelpittet’s picture

Status: Needs work » Closed (outdated)

Drupal 7 reached end-of-life and the D7 version of Organic Groups is no longer being developed. To keep the issue queue focused on supported versions, we’re closing older D7 issues. If you still have questions about using Organic Groups on Drupal 7, feel free to ask. While we won’t fix D7 bugs anymore, we’re happy to offer guidance to help you move forward. You can do so by opening (or reopening) a D7 issue, or by reaching out in the #og channel on Drupal Slack.

If this issue is still relevant for Drupal 10+, please open a follow-up issue or merge request with proposed changes. Contributions are always welcome! 💙

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.