| 5 node.module | node_add($type = NULL) |
| 6 node.pages.inc | node_add($type) |
| 7 node.pages.inc | node_add($type) |
| 8 node.pages.inc | node_add($type) |
Present a node submission form or a set of links to such forms.
File
- modules/
node/ node.module, line 2250 - 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
<?php
function node_add($type = NULL) {
global $user;
$types = node_get_types();
$type = isset($type) ? str_replace('-', '_', $type) : NULL;
// If a node type has been specified, validate its existence.
if (isset($types[$type]) && node_access('create', $type)) {
// Initialize settings:
$node = array(
'uid' => $user->uid,
'name' => $user->name,
'type' => $type,
);
drupal_set_title(t('Submit @name', array('@name' => $types[$type]->name)));
$output = drupal_get_form($type . '_node_form', $node);
}
else {
// If no (valid) node type has been provided, display a node type overview.
foreach ($types as $type) {
if (function_exists($type->module . '_form') && node_access('create', $type->type)) {
$type_url_str = str_replace('_', '-', $type->type);
$title = t('Add a new @s.', array('@s' => $type->name));
$out = '<dt>' . l(drupal_ucfirst($type->name), "node/add/$type_url_str", array('title' => $title)) . '</dt>';
$out .= '<dd>' . filter_xss_admin($type->description) . '</dd>';
$item[$type->name] = $out;
}
}
if (isset($item)) {
uksort($item, 'strnatcasecmp');
$output = t('Choose the appropriate item from the list:') . '<dl>' . implode('', $item) . '</dl>';
}
else {
$output = t('No content types available.');
}
}
return $output;
}
?>Login or register to post comments