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.
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.
Comment | File | Size | Author |
---|---|---|---|
#14 | og-support-multiple-og-reference-2147491-14.patch | 3.94 KB | chiebert |
#4 | 2147491-7.x-2.3-og-node-create-links-more-fields-do-not-test.patch | 3.67 KB | sammys |
#4 | 2147491-4-og-node-create-links-more-fields.patch | 3.63 KB | sammys |
Comments
Comment #1
sammys CreditAttribution: sammys commentedComment #3
sammys CreditAttribution: sammys commentedAmended to use drupal_sort_title. Use this patch for 7.x-2.3.
Comment #4
sammys CreditAttribution: sammys commentedRealised 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.
Comment #5
amitaibu> 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.
Comment #6
namita21 CreditAttribution: namita21 commentedI 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..
Comment #7
amitaibuAre you passing og_node_create_links() the correct value of the field?
Comment #8
namita21 CreditAttribution: namita21 commentedI 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);
}
Comment #9
namita21 CreditAttribution: namita21 commentedIts 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?
Comment #10
namita21 CreditAttribution: namita21 commentedgroup1: 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.
Comment #11
chiebert CreditAttribution: chiebert commentedPatch 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 thenog_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...
Comment #12
chiebert CreditAttribution: chiebert commentedSorry - mucked up the issue summary by accident. Fixing it now...
Comment #13
chiebert CreditAttribution: chiebert commentedPatch with the changes I suggest in #11 above...
Comment #14
chiebert CreditAttribution: chiebert commentedOops - forgot to deal with the different query string for prepopulating the entity reference. This one fixes that...