Same name and namespace in other branches
  1. 4.6.x modules/node.module \node_menu()
  2. 4.7.x modules/node.module \node_menu()
  3. 6.x modules/node/node.module \node_menu()
  4. 7.x modules/node/node.module \node_menu()

Implementation of hook_menu().

File

modules/node/node.module, line 1126
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.

Code

function node_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/content',
      'title' => t('Content management'),
      'description' => t("Manage your site's content."),
      'position' => 'left',
      'weight' => -10,
      'callback' => 'system_admin_menu_block_page',
      'access' => user_access('administer site configuration'),
    );
    $items[] = array(
      'path' => 'admin/content/node',
      'title' => t('Content'),
      'description' => t("View, edit, and delete your site's content."),
      'callback' => 'node_admin_content',
      'access' => user_access('administer nodes'),
    );
    $items[] = array(
      'path' => 'admin/content/node/overview',
      'title' => t('List'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -10,
    );
    if (module_exists('search')) {
      $items[] = array(
        'path' => 'admin/content/search',
        'title' => t('Search content'),
        'description' => t('Search content by keyword.'),
        'callback' => 'node_admin_search',
        'access' => user_access('administer nodes'),
        'type' => MENU_NORMAL_ITEM,
      );
    }
    $items[] = array(
      'path' => 'admin/content/node-settings',
      'title' => t('Post settings'),
      'description' => t('Control posting behavior, such as teaser length, requiring previews before posting, and the number of posts on the front page.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'node_configure',
      ),
      'access' => user_access('administer nodes'),
    );
    $items[] = array(
      'path' => 'admin/content/node-settings/rebuild',
      'title' => t('rebuild permissions'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'node_configure_rebuild_confirm',
      ),
      'access' => user_access('administer nodes'),
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'admin/content/types',
      'title' => t('Content types'),
      'description' => t('Manage posts by content type, including default status, front page promotion, etc.'),
      'callback' => 'node_overview_types',
      'access' => user_access('administer content types'),
    );
    $items[] = array(
      'path' => 'admin/content/types/list',
      'title' => t('List'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -10,
    );
    $items[] = array(
      'path' => 'admin/content/types/add',
      'title' => t('Add content type'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'node_type_form',
      ),
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'node',
      'title' => t('Content'),
      'callback' => 'node_page_default',
      'access' => user_access('access content'),
      'type' => MENU_MODIFIABLE_BY_ADMIN,
    );
    $items[] = array(
      'path' => 'node/add',
      'title' => t('Create content'),
      'callback' => 'node_add',
      'access' => user_access('access content'),
      'type' => MENU_ITEM_GROUPING,
      'weight' => 1,
    );
    $items[] = array(
      'path' => 'rss.xml',
      'title' => t('RSS feed'),
      'callback' => 'node_feed',
      'access' => user_access('access content'),
      'type' => MENU_CALLBACK,
    );
    foreach (node_get_types() as $type) {
      if (function_exists($type->module . '_form')) {
        $type_url_str = str_replace('_', '-', $type->type);
        $items[] = array(
          'path' => 'node/add/' . $type_url_str,
          'title' => drupal_ucfirst($type->name),
          'access' => node_access('create', $type->type),
        );
      }
    }

    // Error pages must to be present in the menu cache and be accessible to
    // all. More often than not these are individual nodes.
    for ($error_code = 403; $error_code <= 404; $error_code++) {
      if (preg_match('|^node/(?P<nid>\\d+)(?:/view)?$|', drupal_get_normal_path(variable_get('site_' . $error_code, '')), $matches) && ($node = node_load($matches['nid']))) {
        $items[] = array(
          'path' => 'node/' . $node->nid,
          'title' => t('View'),
          'callback' => 'node_page_view',
          'callback arguments' => array(
            $node,
          ),
          'access' => TRUE,
          'type' => MENU_CALLBACK,
        );
      }
    }
  }
  else {

    // Add the CSS for this module
    // We put this in !$may_cache so it's only added once per request
    drupal_add_css(drupal_get_path('module', 'node') . '/node.css');
    if (arg(0) == 'node' && is_numeric(arg(1))) {
      $node = node_load(arg(1));
      if ($node->nid) {
        $items[] = array(
          'path' => 'node/' . arg(1),
          'title' => t('View'),
          'callback' => 'node_page_view',
          'callback arguments' => array(
            $node,
          ),
          'access' => node_access('view', $node),
          'type' => MENU_CALLBACK,
        );
        $items[] = array(
          'path' => 'node/' . arg(1) . '/view',
          'title' => t('View'),
          'type' => MENU_DEFAULT_LOCAL_TASK,
          'weight' => -10,
        );
        $items[] = array(
          'path' => 'node/' . arg(1) . '/edit',
          'title' => t('Edit'),
          'callback' => 'node_page_edit',
          'callback arguments' => array(
            $node,
          ),
          'access' => node_access('update', $node),
          'weight' => 1,
          'type' => MENU_LOCAL_TASK,
        );
        $items[] = array(
          'path' => 'node/' . arg(1) . '/delete',
          'title' => t('Delete'),
          'callback' => 'drupal_get_form',
          'callback arguments' => array(
            'node_delete_confirm',
            $node,
          ),
          'access' => node_access('delete', $node),
          'weight' => 1,
          'type' => MENU_CALLBACK,
        );
        $revisions_access = (user_access('view revisions') || user_access('administer nodes')) && node_access('view', $node) && db_result(db_query('SELECT COUNT(vid) FROM {node_revisions} WHERE nid = %d', arg(1))) > 1;
        $items[] = array(
          'path' => 'node/' . arg(1) . '/revisions',
          'title' => t('Revisions'),
          'callback' => 'node_revisions',
          'access' => $revisions_access,
          'weight' => 2,
          'type' => MENU_LOCAL_TASK,
        );
        if (!is_null(arg(3))) {
          $items[] = array(
            'path' => 'node/' . arg(1) . '/revisions/' . arg(3) . '/delete',
            'callback' => 'node_revision_delete',
            'callback arguments' => array(
              arg(1),
              arg(3),
            ),
            'type' => MENU_CALLBACK,
          );
          $items[] = array(
            'path' => 'node/' . arg(1) . '/revisions/' . arg(3) . '/revert',
            'callback' => 'node_revision_revert',
            'callback arguments' => array(
              arg(1),
              arg(3),
            ),
            'type' => MENU_CALLBACK,
          );
        }
      }
    }

    // Content type configuration.
    if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'types') {
      include_once './' . drupal_get_path('module', 'node') . '/content_types.inc';
      if (arg(3) != NULL) {
        $type_name = arg(3);
        $type_name = !empty($type_name) ? str_replace('-', '_', $type_name) : NULL;
        $type = node_get_types('type', $type_name);
        if (!empty($type)) {
          $type_url_str = str_replace('_', '-', $type->type);
          $items[] = array(
            'path' => 'admin/content/types/' . $type_url_str,
            'title' => t($type->name),
            'callback' => 'drupal_get_form',
            'callback arguments' => array(
              'node_type_form',
              $type,
            ),
            'type' => MENU_CALLBACK,
          );
          $items[] = array(
            'path' => 'admin/content/types/' . $type_url_str . '/delete',
            'title' => t('Delete'),
            'callback' => 'drupal_get_form',
            'callback arguments' => array(
              'node_type_delete_confirm',
              $type,
            ),
            'type' => MENU_CALLBACK,
          );
        }
      }
    }
  }
  return $items;
}