I'm working on a project that requires one OG reference field to target group bundle A, another to target group bundle B and the default field to target all group bundles. Each field is on a different group content bundle.

Unfortunately, og_node_create_links() only supports the default field OG_AUDIENCE_FIELD (or og_group_ref) so I would have to reimplement the function in another module. I figure this is something that should live in OG itself so I've patched it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sammys’s picture

Status: Active » Needs review
FileSize
3.33 KB

Status: Needs review » Needs work

The last submitted patch, 1: 2147491-og-node-create-links-more-fields.patch, failed testing.

sammys’s picture

FileSize
3.23 KB

Amended to use drupal_sort_title. Use this patch for 7.x-2.3.

sammys’s picture

Realised that I had changed it to use theme('links'). Restored it to the original rendering. First patch is for 7.x-2.3 and the second is for 7.x-2.x.

amitaibu’s picture

> Unfortunately, og_node_create_links() only supports the default field OG_AUDIENCE_FIELD

This is not correct. You need to pass it the field name explicitly, so in your case where you need 2 fields, you will need to call this function twice.

namita21’s picture

I am facing the same issue:
I have two different bundles and using 2 group audience field og_group_ref and og_group_ref1

I need to create create content links for different groups with prepopulated group audience value.
Right now its just picking value for default field OG_AUDIENCE_FIELD.

Any help is appreciated..

amitaibu’s picture

Are you passing og_node_create_links() the correct value of the field?

namita21’s picture

I haven't change anything yet, its using same function form og_extra module:
function og_extras_node_links() {
$group = og_context();

$types = array();
foreach (node_type_get_types() as $type) {
if (og_is_group_content_type('node', $type->type)) {
$types[$type->type] = $type->type;
}
}

$content = og_node_create_links($group['group_type'], $group['gid'], OG_AUDIENCE_FIELD, NULL, $types);
return drupal_render($content);
}

namita21’s picture

Its picking only the content type with first group and its related group audience, what change I need to make so that it picks content type for second group and its related group audience value?

namita21’s picture

group1: community
content type: announcement, events
group audience: og_group_ref

group2: sub-community
content type: post, article
group audience: og_group_ref1

Right now using og_node_create_links(), its showing only the list of links for creating announcement, events on both community and sub-community group pages.

chiebert’s picture

Issue summary: View changes

Patch in #4 applied cleanly for me (7.x-2.7), but didn't solve the problem. I've got the same scenario as @namita21: Two different group content types, each of which is using a different groups reference field. Only the one that uses the default og_group_ref is showing up in the 'Content create links' block.

Observations:

@namita21: you're referencing the og_extras module in #8 - that's a separate issue that needs to be addressed there, since the function you've referred to is simply calling og_node_create_links() with the default OG_AUDIENCE_FIELD constant.

As for the patch in #4: as @amitaibu points out in #5 (and #7), og_node_create_links() is ambivalent about the actual field used for groups audience. The main problem most of us are running into is upstream, in the cpanels plugin defined in plugins/content_types/node_create_links/node_create_links.inc. I'll bet most of the people in this thread are using Panels to set up their Group page, and they've added the 'Content create links' widget/block that'd defined here.

@amitaibu: The tiny problem with calling og_node_create_links() separately for each groups audience field is that that function returns a complete html element array, which means when it's called more than once it renders as multiple separate item lists (<ul>s, each wrapped in a <div>).

Wouldn't it be better if og_node_create_links() could handle an array of $field_names, and then og_node_create_links_content_type_render() over in the aforementioned cpanels plugin could handle the job of figuring out the list of relevant group audience fields and simply feed it in?

Working on a patch now that hopefully demonstrates this, but doesn't break calls that currently send in a single og reference field...

chiebert’s picture

Issue summary: View changes

Sorry - mucked up the issue summary by accident. Fixing it now...

chiebert’s picture

Patch with the changes I suggest in #11 above...

chiebert’s picture

FileSize
3.94 KB

Oops - forgot to deal with the different query string for prepopulating the entity reference. This one fixes that...