[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/module_builder/templates/ -> node_hooks.template (source)

   1  
   2  /**
   3   * @file
   4   * Defines default templates for node hook functions.
   5   *
   6   * Some of these are duplicated from the "normal" hooks template, because 
   7   * nodes do things a little differently than "normal" nodes. :)
   8   */
   9  
  10  == START hook_node_info ==
  11  
  12  ############## WORK: add INFO to these!!!!
  13    return array(
  14      '%module' => array(
  15        'name' => '', 
  16          /* INFO:  the human-readable name of the node type. Required. */
  17        'module' => '', 
  18          /* INFO: a string telling Drupal how a module's functions map to hooks
  19          (i.e. if module is defined as example_foo, then example_foo_insert will
  20          be called when inserting a node of that type). This string is usually
  21          the name of the module in question, but not always. Required. */
  22        'description' => '',
  23        'help' => '',
  24        'has_title' => '', 
  25        'title_label' => '', 
  26        'has_body' => '',
  27        'body_label' => '',
  28        'min_word_count' => '',
  29        'locked' => '', 
  30          /* INFO:  boolean indicating whether the machine-readable name of this
  31          content type can (FALSE) or cannot (TRUE) be edited by a site
  32          administrator. Optional (defaults to TRUE). */
  33      ),
  34      // add further types as needed
  35    );
  36  == END ==
  37  == START hook_access ==
  38    global $user;
  39  
  40    if ($op == 'create') {
  41      return user_access('create %name');
  42    }
  43  
  44    if ($op == 'update' || $op == 'delete') {
  45      if (user_access('edit own %name') && ($user->uid == $node->uid)) {
  46        return TRUE;
  47      }
  48    }
  49  == END ==
  50  
  51  == START hook_perm ==
  52    return array('create %name', 'edit own %name');
  53  == END ==
  54  
  55  == START hook_form ==
  56    // The site admin can decide if this node type has a title and body, and how
  57    // the fields should be labeled. We need to load these settings so we can
  58    // build the node form correctly.
  59    $type = node_get_types('type', $node);
  60  
  61    if ($type->has_title) {
  62      $form['title'] = array(
  63        '#type' => 'textfield',
  64        '#title' => check_plain($type->title_label),
  65        '#required' => TRUE,
  66        '#default_value' => $node->title,
  67        '#weight' => -5
  68      );
  69    }
  70  
  71    if ($type->has_body) {
  72      // In Drupal 6, we can use node_body_field() to get the body and filter
  73      // elements. This replaces the old textarea + filter_form() method of
  74      // setting this up. It will also ensure the teaser splitter gets set up
  75      // properly.
  76      $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
  77    }
  78  
  79    // TODO: Enter additional form elements
  80  
  81    return $form;
  82  == END ==
  83  
  84  == START hook_validate ==
  85    // TODO: Enter form validation code here
  86    if (0) { // if bad stuff
  87      form_set_error('FORM ELEMENT NAME', t('TODO: Write an error message.'));
  88    }
  89  == END ==
  90  
  91  == START hook_insert ==
  92    // TODO: Enter database insertion query here, for example:
  93    // db_query("INSERT INTO {node_example} (vid, nid, color, quantity) VALUES (%d, %d, '%s', %d)", $node->vid, $node->nid, $node->color, $node->quantity);
  94  == END ==
  95  
  96  == START hook_update ==
  97    // if this is a new node or we're adding a new revision,
  98    if ($node->revision) {
  99      %module_insert($node);
 100    }
 101    else {
 102      // TODO: Enter database update query here, for example:
 103      // db_query("UPDATE {node_example} SET color = '%s', quantity = %d WHERE vid = %d", $node->color, $node->quantity, $node->vid);
 104    }
 105  == END ==
 106  
 107  == START hook_delete ==
 108    // TODO: Enter database deletion query here, for example:
 109    // db_query('DELETE FROM {node_example} WHERE nid = %d', $node->nid);
 110  == END ==
 111  
 112  == START hook_load ==
 113    // TODO: Obtain and return additional fields added to the node type, for example:
 114    // $additions = db_fetch_object(db_query('SELECT color, quantity FROM {node_example} WHERE vid = %d', $node->vid));
 115    // return $additions;
 116  == END ==
 117  
 118  == START hook_view ==
 119    // TODO: Insert additional code (call to theme functions, etc.) to execute when viewing a node, for example:
 120    // $node = node_prepare($node, $teaser);
 121    // $node->content['myfield'] = array(
 122    //   '#value' => theme('node_example_order_info', $node),
 123    //   '#weight' => 1,
 124    // );
 125  
 126    return $node;
 127  == END ==


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7