1.20.x node.pages.inc node_add_page()

Page callback: Displays add content links for available content types.

Redirects to node/add/[type] if only one content type is available.

See also

node_menu()

File

modules/node/node.pages.inc, line 29
Callbacks for adding, editing, and deleting content and managing revisions.

Code

function node_add_page() {
  $content = array();
  // Only use node types to which the user has access.
  foreach (node_type_get_types() as $node_type) {
    if (node_access('create', $node_type->type)) {
      $href_url_friendly = str_replace('_', '-', $node_type->type);
      $content[$node_type->type] = array(
        'title' => t($node_type->name),
        'href' => 'node/add/' . $href_url_friendly,
        'localized_options' => array('html' => FALSE),
        'description' => t($node_type->description),
      );
    }
  }
  // If there is more than one content type, sort them by title instead of
  // machine name before displaying the list of links...
  if (count($content) !== 1) {
    backdrop_sort($content, array('title'));
  }
  // ...otherwise bypass the node/add listing and go directly to the
  // node/add/[type] page of the single content type.
  else {
    $item = array_shift($content);
    backdrop_goto($item['href']);
  }
  return theme('node_add_list', array('content' => $content));
}