Same name and namespace in other branches
  1. 4.6.x modules/node.module \node_add()
  2. 5.x modules/node/node.module \node_add()
  3. 6.x modules/node/node.pages.inc \node_add()
  4. 7.x modules/node/node.pages.inc \node_add()

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

File

modules/node.module, line 1792
The core that allows content to be submitted to the site.

Code

function node_add($type) {
  global $user;

  // If a node type has been specified, validate its existence.
  if (array_key_exists($type, node_get_types()) && node_access('create', $type)) {

    // Initialize settings:
    $node = array(
      'uid' => $user->uid,
      'name' => $user->name,
      'type' => $type,
    );
    $output = node_form($node);
    drupal_set_title(t('Submit %name', array(
      '%name' => node_get_name($node),
    )));
  }
  else {

    // If no (valid) node type has been provided, display a node type overview.
    foreach (node_get_types() as $type => $name) {
      if (node_access('create', $type)) {
        $out = '<dt>' . l($name, "node/add/{$type}", array(
          'title' => t('Add a new %s.', array(
            '%s' => $name,
          )),
        )) . '</dt>';
        $out .= '<dd>' . implode("\n", module_invoke_all('help', 'node/add#' . $type)) . '</dd>';
        $item[$name] = $out;
      }
    }
    if (isset($item)) {
      uksort($item, 'strnatcasecmp');
      $output = t('Choose the appropriate item from the list:') . '<dl>' . implode('', $item) . '</dl>';
    }
    else {
      $output = t('You are not allowed to create content.');
    }
  }
  return $output;
}