Automatically putting a user's post into an organic group
The final result is in the (as yet unreleased, but if you want the code we'll send it) special treatment module.
Some test ouput and discovery of key function along the way:
<?php
'og_groups' =>
array (
11054 =>
array (
'title' => 'A Center for Development and Entrepreneurship',
'type' => 'partner',
'status' => '1',
'nid' => '11054',
'og_role' => '0',
'is_active' => '1',
'is_admin' => '1',
'uid' => '1',
'mail_type' => NULL,
'created' => '1222100233',
'changed' => '1222280936',
),
),
'og_email' => '2',
'og_groups' => array ( ), 'og_email' => '1', ))
?>
For user #1, editing an existing form:
<?php
'og_initial_groups' =>
array (
'#type' => 'value',
'#value' => NULL,
),
'og_nodeapi' =>
array (
'visible' =>
array (
'og_groups' =>
array (
'#type' => 'checkboxes',
'#title' => 'Audience',
'#attributes' =>
array (
'class' => 'og-audience',
),
'#options' =>
array (
11054 => 'A Center for Development and Entrepreneurship',
),
'#required' => false,
'#description' => 'Show this post in this group.',
'#default_value' => NULL,
'#multiple' => true,
),
),
),
?>
When there's a value:
<?php
'og_initial_groups' =>
array (
'#type' => 'value',
'#value' =>
array (
0 => 11054,
),
),
?>
For a regular user:
<?php
'og_invisible' =>
array (
'og_groups_inaccessible' =>
array (
'#type' => 'value',
'#value' =>
array (
),
),
),
'og_initial_groups' =>
array (
'#type' => 'value',
'#value' => NULL,
),
?>
Agaric's new friend, organic groups' save ancestry function:
<?php
function og_save_ancestry($node) {
if (og_is_group_post_type($node->type)) {
$sql = "DELETE FROM {og_ancestry} WHERE nid = %d";
db_query($sql, $node->nid);
if (is_array($node->og_groups)) {
$node->og_groups = array_unique($node->og_groups);
foreach ($node->og_groups as $gid) {
$sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) VALUES (%d, %d, %d)";
db_query($sql, $node->nid, $gid, $node->og_public);
}
}
}
}
?>
<?php
'og_initial_groups' =>
array (
'#type' => 'value',
'#value' =>
array (
0 => 11054,
),
),
'og_nodeapi' =>
array (
'visible' =>
array (
'og_groups' =>
array (
'#type' => 'checkboxes',
'#title' => 'Audience',
'#attributes' =>
array (
'class' => 'og-audience',
),
'#options' =>
array (
11054 => 'A Center for Development and Entrepreneurship',
),
'#required' => false,
'#description' => 'Show this post in this group.',
'#default_value' =>
array (
0 => 11054,
),
'#multiple' => true,
),
),
),
?>
Resolution
More like this
- Do not allow users to post content to organic groups except from within an organic group
- Figuring out Organic Groups Project module integration: output of project module's link altering hook
- Allow users to assign issues to other people in the project group (organic groups and project module integration)
- Everyone's Voices, Nobody's Noise post-submission strategy session with Nathaniel Catchpole
- Update a Debian user's password and passkey and grant sudo access


Comments
Post new comment