| Versions | |
|---|---|
| 4.7 | node_add($type) |
| 5 | node_add($type = NULL) |
| 6 – 7 | node_add($type) |
Present a node submission form or a set of links to such forms.
modules/
<?php
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;
}
?>