node_add

Versions
4.6 – 4.7
node_add($type)
5
node_add($type = NULL)
6 – 7
node_add($type)

Present a node submission form or a set of links to such forms.

▾ 1 function calls node_add()

node_page in modules/node.module
Menu callback; dispatches control to the appropriate operation handler.

Code

modules/node.module, line 1425

<?php
function node_add($type) {
  global $user;

  $edit = $_POST['edit'];

  // If a node type has been specified, validate its existence.
  if (in_array($type, node_list()) && node_access('create', $type)) {
    // Initialize settings:
    $node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type);

    // Allow the following fields to be initialized via $_GET (e.g. for use
    // with a "blog it" bookmarklet):
    foreach (array('title', 'teaser', 'body') as $field) {
      if ($_GET['edit'][$field]) {
        $node[$field] = $_GET['edit'][$field];
      }
    }
    $output = node_form($node);
    drupal_set_title(t('Submit %name', array('%name' => node_invoke($node, 'node_name'))));
  }
  else {
    // If no (valid) node type has been provided, display a node type overview.
    foreach (node_list() as $type) {
      if (node_access('create', $type)) {
        $out = '<li>';
        $out .= ' '. l(node_invoke($type, 'node_name'), "node/add/$type", array('title' => t('Add a new %s.', array('%s' => node_invoke($type, 'node_name')))));
        $out .= " <div style=\"margin-left: 20px;\">". implode("\n", module_invoke_all('help', 'node/add#'. $type)) .'</div>';
        $out .= '</li>';
        $item[node_invoke($type, 'node_name')] = $out;
      }
    }

    if (isset($item)) {
      ksort($item);
      $output = t('Choose the appropriate item from the list:') .'<ul>'. implode('', $item) .'</ul>';
    }
    else {
      $output = message_access();
    }
  }

  return $output;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.