function node_add_page

You are here

7 node.pages.inc node_add_page()
6 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()

3 string references to 'node_add_page'
drupal-6.bare.database.php in modules/simpletest/tests/upgrade/drupal-6.bare.database.php
Bare installation of Drupal 6.17, for test purposes.
drupal-6.filled.database.php in modules/simpletest/tests/upgrade/drupal-6.filled.database.php
Filled installation of Drupal 6.17, for test purposes.
node_menu in modules/node/node.module
Implements hook_menu().

File

modules/node/node.pages.inc, line 24
Page callbacks for adding, editing, deleting, and revisions management for content.

Code

function node_add_page() {
  $item = menu_get_item();
  $content = system_admin_menu_block($item);
  // Bypass the node/add listing if only one content type is available.
  if (count($content) == 1) {
    $item = array_shift($content);
    drupal_goto($item['href']);
  }
  return theme('node_add_list', array('content' => $content));
}

Comments

On the /node/add page, all content types are displayed that the viewing user has permission to create. I created a different page, where I wanted to only show certain content types, even if the viewing user had permissions to create more than what I wanted to show. (I was shooting for better organization of a large number of content types, and also hiding "supplemental" content types that don't make sense to exist on their own as "content" -- I frequently create content types to solve data storage problems, and don't always want the user to see these types when going to the create content landing page)

The below code works to return a list that only contains content types listed in the "show these only" array. Please note that this does not affect permissions. If you don't want a user creating a certain content type, then change the permissions -- this is just for aesthetic reorganization of content type lists.

<?php
function custom_administration_add_content_page(){
   
//fake out system_admin_menu_block() to get content type links
   
$links = system_admin_menu_block(array('path'=>'node/add'));
   
//build a list of types to show by content type machine name
   
$show_these_only= array(
       
'page',
       
'content_type_to_show'
   
);
   
//build a new array of reduced items
   
foreach($links as $link){
       
//get which content type this is from access arguments array
       
$args = unserialize($link['access_arguments']);
       
$type=$args[1];
        if(
in_array($type,$show_these_only)){
           
$content[] = $link;
        }
    }
   
//use the same theme and return
   
$output = theme('node_add_list',$content);
    return
$output;
}
?>

i meant for this to be on d6 page.. from a glance at d7 code it should work there, too -- but beware, it was only tested on d6

In d7

system_admin_menu_block(array('path'=>'node/add', 'tab_root' => 'node/add'));