Hi,
OG has an "Audience checkboxes" setting
Show each subscribed group as a checkbox in the Audience section. This enables user to place her post into multiple groups. If unchecked, simplify the user interface by omitting the checkboxes and assuming user wants to post into the current group. Group administrators always see checkboxes.
I wanted og_galleries to check this setting too, so that if Audience was unchecked, only galleries from the current group could be chosen. That seems more consistant with what the Audience button is doing and could help sites with lots of groups simplify the number of galleries that show up to be selected.
Any ways, I hacked something together in og_galleries_form_alter based on code I saw in og.module and og_galleries.module. I'm sure there has to be a better way to do this (since I just copied and modified existing code), but it seems to give me the behavior I want.
// remove vocabs that belong to other groups from categories
// and move galleries options from categories fieldset to galleries fieldset
// the og module already figured out which groups belong as options on this form, so get the list
$groups = (array) $form['og_nodeapi']['visible']['og_groups']['#options'];
//check to see if we should just provide a simple view (per og audience checkbox setting)
$simple = !user_access('administer organic groups') && !variable_get('og_audience_checkboxes', TRUE);
if ($simple)
{
// get the gid passed by the server
if ($_SERVER["REQUEST_METHOD"] == 'GET') {
$gids = $_GET['gids'];
};
// get the node
$node = $form['#node'];
// look up node subscriptions to get the node object and to make sure the user has access to the
// passed gid
$subs = og_get_subscriptions($node->uid);
if ($gids)
{
$groups = array();
$keys = array_intersect($gids, array_keys($subs));
foreach ($keys as $gid) {
$groups[$gid] = $subs[$gid]['title'];
}
}
}
Better way to do it? Is this a desirable feature?
Patrick
Comments
Comment #1
karens commentedMakes sense to me, but I found a much simpler way to do it, and have just committed it. I just used:
Comment #2
karens commentedForgot to set the status. You can reset it if it doesn't work for you.
Comment #3
pcdonohue commentedYes, that certainly seems simpler. Thanks for bearing with me as I muddle through your code.
Patrick
Comment #4
spjsche commentedCould this feature be implemented in the OG Groups module.
Comment #5
karens commentedI don't understand the question. OG already has the simplified feature, we're just just adjusting the groups we display to match what OG is doing.
Comment #6
pcdonohue commentedKaren,
I used the code you posted and it didn't work. Essentially $groups was coming up as empty, so all the galleries ended up in the Categories field again (rather than just the current group in the Galleries field)
I think the array_diff call is reversed, so that it should be
because $invisible seems to hold the current gid and $available seems to be empty.
Patrick
Comment #7
spjsche commentedThanks for the response, but the reason I ask is because it does not work on my site.
I have the latest version for 4.7.5.
I have tried to uncheck the "Audience checkboxes" and toggle the "Audience required" to optional and required, but the audience checkboxes still show for all users.
Also I posed this question the other day http://drupal.org/node/109078, and this feature will sort the problem out.
Perhaps I have something else checked or unchecked that should not be.
Stephen
Comment #8
karens commented@spjsche, you are trying to change something in the OG module and OG Galleries has no control over what OG does, so the issue you posted on OG is the right place to persue that question.
@pcdonohue, it looks like OG is not handling that the way I thought it was, so I need to dig into it and make sure of the right fix.
Comment #9
karens commented@pcdonohue, can you try the following:
It looks like the 'visible' and 'invisible' groups are mutually exclusive. One is empty and the other not. In the simple version, we want the 'invisible' value, otherwise we want the 'visible' value. I'm pretty sure this will work right, but could you confirm it works in your situation before I commit it?
Comment #10
spjsche commentedOne simple, but maybe stupid question.
How do you know which Group the content type is trying to submit to (which is the current group?), if you belong to more than one group.
Comment #11
pcdonohue commentedThis seems to work fine with one little addition to cast the result to an array
otherwise I get an unsupported operand error.
thanks!
Patrick
Comment #12
karens commented@pcdonohue - Thanks! I'll get this committed.
@spjshe - I don't know how OG makes decisions about what group to use if you belong to more than one. You should ask that question on the OG issue queue or as a followup to the OG issue you already posted.
Comment #13
pcdonohue commentedspjsche,
the group id is passed via the url
for example
http://.../drupal/node/add/image?gids[]=47
But generally that happens if you're using the group details block... in the group details block for a specific group, you can click on "create image" and it will link to the above url already.
Patrick
Comment #14
spjsche commentedThanks for the answer
Comment #15
(not verified) commented