function onlyone_add_page in Allow a content type only once (Only One) 7
Page callback: Displays add content links for configured content types.
Redirects to onlyone/add/[type] if only one content type is available.
See also
2 string references to 'onlyone_add_page'
- onlyone_menu in ./
onlyone.module - Implements hook_menu().
- onlyone_menu_link_alter in ./
onlyone.module - Implements hook_menu_link_alter().
File
- ./
onlyone.pages.inc, line 15 - Page callbacks for adding content.
Code
function onlyone_add_page() {
// Only use node types the user has access to.
$item = menu_get_item('node/add');
$content = system_admin_menu_block($item);
// Getting the configured content types.
$onlyone_node_types = variable_get('onlyone_node_types');
// Filtering only the configured content types.
foreach ($content as $key => $element) {
// Getting the content type name.
$content_type = substr($element['href'], 9);
// Removing not configured content types.
if (!in_array($content_type, $onlyone_node_types)) {
unset($content[$key]);
}
}
// 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,
));
}