You are here

function spaces_og_nodeapi in Spaces 5.2

Same name and namespace in other branches
  1. 6.3 spaces_og/spaces_og.module \spaces_og_nodeapi()
  2. 6 spaces_og/spaces_og.module \spaces_og_nodeapi()
  3. 6.2 spaces_og/spaces_og.module \spaces_og_nodeapi()

Implementation of hook_nodeapi().

File

./spaces_og.module, line 531

Code

function spaces_og_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'prepare':
      if (og_is_group_type($node->type) && ($space = spaces_load('og', $node->nid))) {
        $node->space_prefix = $space->prefix;
      }
      else {
        if ($space = spaces_get_space()) {
          _spaces_enforce_feature($space->sid, $node);
        }
      }
      break;
    case 'submit':

      // switch node's group if specified
      if (!og_is_omitted_type($node->type)) {
        if (isset($node->spaces_og['gid']) && !in_array($node->spaces_og['gid'], $node->og_groups)) {
          $new_gid = $node->spaces_og['gid'];
          _spaces_enforce_feature($new_gid, $node);
        }
      }
      break;
    case 'insert':
    case 'update':

      // save prefix & preset from node form information
      if (og_is_group_type($node->type) && isset($node->context_prefix['prefix'])) {
        $space = spaces_load('og', $node->nid);
        $space->prefix = $node->context_prefix['prefix'];
        $space->preset = $node->preset;

        // Save that shiz
        $space->save_once = TRUE;

        // Custom flag that kills node_save() recursion
        spaces_save($space);
      }
      break;
    case 'delete':
      if (og_is_group_type($node->type)) {
        $space = spaces_load('og', $node->nid);
        if ($space) {
          spaces_delete($space);
        }
      }
      break;
  }
}