addanother.module in Add Another 7
Same filename and directory in other branches
Presents users with an option to create another node of the same type after a node is added.
File
addanother.moduleView source
<?php
/**
* @file
* Presents users with an option to create another node of the same type after a
* node is added.
*/
/**
* Implement hook_help().
*/
function addanother_help($path, $arg) {
$output = '';
switch ($path) {
case "admin/help#addanother":
$output = '<p>' . t("Presents users with an option to create another node of the same type after a node is added.") . '</p>';
return $output;
case 'admin/config/content/addanother':
$output = '<p>' . t('Here you can select the content types for which an <em>"Add another..."</em> message will be displayed. After creating a new content node, users with the <a href="@addanother_permission">use add another</a> permission will receive a message allowing them to add another content node of the same type.', array(
'@addanother_permission' => url('admin/config/people/permissions', array(
'fragment' => 'module-addanother',
)),
)) . '</p>';
return $output;
}
}
/**
* Implement hook_permission().
*/
function addanother_permission() {
return array(
'administer add another' => array(
'title' => t('Administer Add Another'),
'description' => t('Configure content types for Add Another'),
),
'use add another' => array(
'title' => t('Use Add Another'),
'description' => t('Use the "Add Another..." link to create more content'),
),
);
}
/**
* Implement hook_menu().
*/
function addanother_menu() {
$items = array();
$items['admin/config/addanother'] = array(
'title' => 'Add another',
'description' => 'Modify which node types display the Add another message.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'addanother_admin',
),
'access arguments' => array(
'administer add another',
),
'type' => MENU_NORMAL_ITEM,
);
$items['node/%/addanother'] = array(
'title' => 'Add another',
'page callback' => 'addanother_goto',
'page arguments' => array(
1,
),
'access callback' => 'addanother_access',
'access arguments' => array(
1,
),
'weight' => 5,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
/**
* Check if we should display the Add another verbage on a node.
*/
function addanother_access($nid) {
$allowed_nodetypes = variable_get('addanother_nodetypes', array());
$node = node_load($nid);
if (arg(2) == "edit" && !variable_get('addanother_tab_edit', FALSE)) {
return FALSE;
}
if ($node && isset($allowed_nodetypes[$node->type]) && $allowed_nodetypes[$node->type] && user_access('use add another') && node_access('create', $node->type)) {
return TRUE;
}
return FALSE;
}
/**
* Takes the user to the node creation page for the type of a given node.
*/
function addanother_goto($nid) {
if ($node = node_load($nid)) {
drupal_goto('node/add/' . $node->type);
}
else {
drupal_goto('node/add');
}
}
/**
* This function sets up the admin/settings/addanother settings page.
*/
function addanother_admin($form, &$form_state) {
$form['addanother_nodes'] = array(
'#type' => 'fieldset',
'#title' => t('Content settings'),
);
$form['addanother_nodes']['addanother_nodetypes'] = array(
'#type' => 'checkboxes',
'#title' => t('Enable Add another for these content types'),
'#options' => node_type_get_names(),
'#default_value' => variable_get('addanother_nodetypes', array()),
'#description' => t('An <em>Add another</em> message will be shown after creating these content types'),
);
$form['addanother_display'] = array(
'#type' => 'fieldset',
'#title' => t('Display settings'),
);
$form['addanother_display']['addanother_message'] = array(
'#type' => 'checkbox',
'#title' => t('Display the Add another message after node creation.'),
'#default_value' => variable_get('addanother_message', TRUE),
);
$form['addanother_display']['addanother_tab'] = array(
'#type' => 'checkbox',
'#title' => t('Display the Add another tab on supported node types.'),
'#default_value' => variable_get('addanother_tab', FALSE),
);
$form['addanother_display']['addanother_tab_edit'] = array(
'#type' => 'checkbox',
'#title' => t('Also display the Add another tab on supported node edit pages.'),
'#default_value' => variable_get('addanother_tab_edit', FALSE),
);
return system_settings_form($form);
}
/**
* Implement hook_node_insert().
*/
function addanother_node_insert($node) {
$allowed_nodetypes = variable_get('addanother_nodetypes', array());
if (user_access('use add another') && isset($allowed_nodetypes[$node->type]) && $allowed_nodetypes[$node->type]) {
$_addanother_message = t('Add another <a href="@typeurl">%type</a>.', array(
'@typeurl' => url('node/add/' . str_replace('_', '-', $node->type)),
'%type' => node_type_get_name($node),
));
drupal_set_message($_addanother_message, 'status', FALSE);
}
}
Functions
Name | Description |
---|---|
addanother_access | Check if we should display the Add another verbage on a node. |
addanother_admin | This function sets up the admin/settings/addanother settings page. |
addanother_goto | Takes the user to the node creation page for the type of a given node. |
addanother_help | Implement hook_help(). |
addanother_menu | Implement hook_menu(). |
addanother_node_insert | Implement hook_node_insert(). |
addanother_permission | Implement hook_permission(). |