nodefamily_nodeapi

Versions
5
nodefamily_nodeapi(&$node, $op, $teaser = NULL, $page = NULL)

Implementation of hook_nodeapi().

Code

contributions/nodefamily/nodefamily.module, line 160

<?php
function nodefamily_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {

  switch($op) {
    case 'insert':
        $parents = nodefamily_get_parent_types($node->type);
        $children = nodefamily_get_child_types($node->type);
    
        if ($parents) {
          foreach ($parents as $parent_typename) {
            nodefamily_relatives_set_parent($parent_typename, $node->uid, $node);
          }
        }
        if ($children) {
          foreach ($children as $child_typename) {
            nodefamily_relatives_set_child($node, $child_typename, $node->uid);
          }
        }
        break;
        
    case 'delete':
        nodefamily_relation_remove_parents($node);
        nodefamily_relation_remove_children($node);
        break;
        
    case 'validate':
        if (!$node->nid && user_access('administer nodes')) {
          if ($account = user_load(array('name' => $node->name))) {
            $node->uid = $account->uid;
          }
          else {
            $node->uid = 0;
          }
        }
        
        if (!$node->nid && nodefamily_content_type_is_max($node->type, $node->uid)) {
           form_set_error('name', t("You can't create more nodes of this type for this user."));
           $form = NULL;
        }
        break;
    case 'submit':
        if ($node->nid && user_access('administer nodes')) {
          $parents = nodefamily_get_parent_types($node->type);
          $children = nodefamily_get_child_types($node->type);
          $oldnode = node_load($node->nid);          
          if ($oldnode->uid != $node->uid) {
            //we have to update the relations because the node author changed
            if ($parents) {
              nodefamily_relation_remove_parents($node);
              foreach ($parents as $parent_typename) {
                nodefamily_relatives_set_parent($parent_typename, $node->uid, $node);
              }
            }
            if ($children) {
              nodefamily_relation_remove_children($node);
              foreach ($children as $child_typename) {
                nodefamily_relatives_set_child($node, $child_typename, $node->uid);
              }  
            }
          }
        }
        break;

    default:
  }
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.