function node_add

You are here

7 node.pages.inc node_add($type)
4.6 node.module node_add($type)
4.7 node.module node_add($type)
5 node.module node_add($type = NULL)
6 node.pages.inc node_add($type)

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

1 call to node_add()
node_page in modules/node.module
Menu callback; dispatches control to the appropriate operation handler.

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;
}