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.
By SomebodySysop on
I posted this in OG issues, but I really need to get a response as I'm on a time critical project.
I'm trying to insert a node into my database and assign it to an OG group programmatically. This is the code I'm attempting to use, but which does not work..
$title = 'Test Title';
$body = 'Test Body';
$gid = 323;
$group = node_load($gid);
$groupName = $group->title;
$node = new stdClass();
$node = array();
$node['type'] = 'brix';
$node['uid'] = 1;
$node['title'] = $title;
$node['body'] = $body;
$node['og_groups'][0] = $gid;
$node['og_groups_names'][0] = $groupName;
if ($node = node_submit($node)) {
node_save($node);
}
The node is inserted with all data except group info. How do I accomplish this?
Comments
Found the answer
Knocked around with this for a few days. Apparently, I needed a couple lines after node_save to add the node info to the og_ancestry table:
This works.
Another day saved
Thanx for taking the trouble to post this snippet. I am building a default group posts module to give a webmaster the opportunity to create a default group with it's own set of posts (of all kinds of cck contentypes). Creating a new group then simply clones all groupposts of this default group and assigns them to the newly created group.
Got the thing working now.
Egbert - webdevelopment and implementation - www.overboord.nl
Will you make your module available?
Hi, I am looking for a way to create a default group with subgroups and different permissions for subgroups. Would it be possible to create groups like this with the module you are working on? I tried the skeleton module, but that saves group posts as book pages. Also will you make your module available to other Drupal users?
No, you cannot use it to
No, you cannot use it to create subgroups, although I think you could extend it. Never looked into subgroups. (Just started using OG as from end of may)
The module itself is working but is more a larve than a fullgrown module. It takes some nodes, which are wiki group posts and copies them and changes some of the group related settings.
It does what it needs to do in a very specific niche.
I do not have time to change it into something worthy of sharing.
You can have the code though ifyou want to play with it? No warranties and sorry for the mess....
Egbert - webdevelopment and implementation - www.overboord.nl
for D6
For D6 i did this in a nodeapi $op = insert when creating a group node to automatically create a wiki node within my new group:
Peter Lindstrom
LiquidCMS - Content Solution Experts
Thanks for the stuff, I still have problem
hello,
I used your code, everything works fine and the path alias creating 2 times.
One is normal from alias settings and one from code.
Please tell me how can i stop the automatic path alias two avoid conflicts.
Thanks in advance
try commenting out this
try commenting out this line:
$wiki->path = "wiki/" . $path;
Peter Lindstrom
LiquidCMS - Content Solution Experts
thanks for the reply, but
Hi there,
I am trying to use the path from the code. Not the automated alias path. Please help me how to achieve this ?
Thanks in Advance.
Access rights are not right when creating wiki nodes
I'm also creating wiki nodes to og pretty much similar way, but I'm having problems with wiki node's access rights. When user subscribes to group they don't see edit buttons for the wiki nodes until author saves the node again. I found out that node_access table had gid value 0 for those nodes when created. I think it has something to do with the og_access module and granting rights but I couldn't figure it out. Any help would be appreciated.