function filedepot_entity_insert in filedepot 7
Implementation of hook_entity_insert().
If OG Mode enabled, create a new top level filedepot folder
File
- ./
filedepot.module, line 1348 - filedepot.module Filedepot: File Management Module developed by Nextide www.nextide.ca Full featured document managment module with a desktop application feel. Integrated Organic Group, Role and User permissions to secure folders, automated…
Code
function filedepot_entity_insert($entity, $type) {
global $user;
// Need to support both versions (1.x and 2.x) of the OG module where 2.x moved away from a group specific entity
if ($type == 'group' and $entity->gid > 0 or $type == 'node' and isset($entity->group_group) and !function_exists('og_get_group')) {
if (variable_get('filedepot_auto_create_group_rootfolder_enabled', 0) == 1) {
/* Admin is being added to the OG Group. This happens when the group is first created but
* will also occur if another admin is added so we need to test for this.
* If first Admin - new Group being created then create a new ROOT level filedepot folder */
if ($type == 'node') {
$gid = $entity->nid;
$label = $entity->title;
}
else {
$gid = $entity->gid;
$label = $entity->label;
}
if (db_query("SELECT count(*) FROM {filedepot_categories} WHERE group_nid=:gid AND pid=0", array(
':gid' => $gid,
))
->fetchField() == 0) {
$node = new stdClass();
$node->type = 'filedepot_folder';
node_object_prepare($node);
$node->language = LANGUAGE_NONE;
$node->uid = $user->uid;
$node->name = $user->name;
$node->title = check_plain($label);
$node->filedepot_folder_desc[LANGUAGE_NONE][0]['value'] = 'Group Root Folder';
$node->parentfolder = 0;
$node->inherit = 0;
$node->gid = $gid;
node_save($node);
watchdog('filedepot', "New Organic Group created @name - new filedepot folder created.", array(
'@name' => $label,
));
}
}
}
}