addanother.module

  1. cis7 sites/all/modules/ulmus/addanother/addanother.module
  2. cle7 sites/all/modules/ulmus/addanother/addanother.module
  3. ecd7 sites/all/modules/ulmus/addanother/addanother.module
  4. elmsmedia7 sites/all/modules/ulmus/addanother/addanother.module
  5. harmony7 sites/all/modules/ulmus/addanother/addanother.module
  6. icor7 sites/all/modules/ulmus/addanother/addanother.module
  7. meedjum_blog7 sites/all/modules/ulmus/addanother/addanother.module
  8. mooc7 sites/all/modules/ulmus/addanother/addanother.module

Presents users with an option to create another node of the same type after a node is added.

Functions

Namesort descending Description
addanother_access Check if we should display the Add another verbage on a node.
addanother_admin_paths Implement hook_admin_paths().
addanother_form_alter Implement hook_form_alter().
addanother_form_node_type_form_alter Alter content type settings to add our options.
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_form_message_submit Submit handler if the normal submit button was pressed, however the node has the 'message' feature enabled.
addanother_node_form_submit Submit handler for the 'Save and add another' button. This allows a redirect to be set if this was the button pressed.
addanother_permission Implement hook_permission().
addanother_theme Implement hook_theme().
theme_addanother_button_message Displays a message and link to the added/edited node after submit
theme_addanother_message_message Displays a message and link to the added/edited node after submit
_addanother_get_node_from_form_state Internal helper function to get the node from a $form_state
_addanother_node_add_path Return the best possible path to provide to the user to create another node.
_addanother_node_type_url Returns node type string acceptable for URL.
_addanother_quelch_message Remove the default Drupal node creation message.

File

sites/all/modules/ulmus/addanother/addanother.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Presents users with an option to create another node of the same type after a
  5. * node is added.
  6. */
  7. /**
  8. * Implement hook_help().
  9. */
  10. function addanother_help($path, $arg) {
  11. if ($path == "admin/help#addanother") {
  12. return '<p>' . t("Presents users with an option to create another node of the same type after a node is added.") . '</p>';
  13. }
  14. }
  15. /**
  16. * Implement hook_permission().
  17. */
  18. function addanother_permission() {
  19. return array(
  20. 'administer add another' => array(
  21. 'title' => t('Administer Add Another'),
  22. 'description' => t('Configure content types for Add Another'),
  23. ),
  24. 'use add another' => array(
  25. 'title' => t('Use Add Another'),
  26. 'description' => t('Use the "Add Another..." link or button to create additional content'),
  27. ),
  28. );
  29. }
  30. /**
  31. * Implement hook_menu().
  32. */
  33. function addanother_menu() {
  34. $items = array();
  35. $items['node/%node/addanother'] = array(
  36. 'title' => 'Add another',
  37. 'page callback' => 'addanother_goto',
  38. 'page arguments' => array(1),
  39. 'access callback' => 'addanother_access',
  40. 'access arguments' => array(1),
  41. 'weight' => 5,
  42. 'type' => MENU_LOCAL_TASK,
  43. );
  44. return $items;
  45. }
  46. /**
  47. * Takes the user to the node creation page for the type of a given node.
  48. */
  49. function addanother_goto($node) {
  50. drupal_goto('node/add/' . _addanother_node_type_url($node->type));
  51. }
  52. /**
  53. * Implement hook_admin_paths().
  54. */
  55. function addanother_admin_paths() {
  56. $paths = array(
  57. 'node/*/addanother' => TRUE,
  58. );
  59. return $paths;
  60. }
  61. /**
  62. * Check if we should display the Add another verbage on a node.
  63. */
  64. function addanother_access($node) {
  65. if (!node_access('create', $node->type)) return FALSE;
  66. if (arg(2) == "edit" &&
  67. !variable_get('addanother_tab_edit_' . $node->type, FALSE)) {
  68. return FALSE;
  69. }
  70. if ($node && variable_get('addanother_tab_' . $node->type, FALSE)
  71. && user_access('use add another')) {
  72. return TRUE;
  73. }
  74. return FALSE;
  75. }
  76. /**
  77. * Alter content type settings to add our options.
  78. */
  79. function addanother_form_node_type_form_alter(&$form, &$form_state) {
  80. if (isset($form['#node_type'])) {
  81. $form['addanother_display'] = array(
  82. '#type' => 'fieldset',
  83. '#title' => t('Add another settings'),
  84. '#collapsible' => TRUE,
  85. '#group' => 'additional_settings',
  86. );
  87. $form['addanother_display']['addanother_button'] = array(
  88. '#type' => 'checkbox',
  89. '#title' => t('Display Add another button on node add form.'),
  90. '#default_value' => variable_get('addanother_button_' . $form['#node_type']->type, FALSE),
  91. '#description' => t('Enable this checkbox if you want to provide a "Save and add another" button on the node add form for your users.'),
  92. );
  93. $form['addanother_display']['addanother_message'] = array(
  94. '#type' => 'checkbox',
  95. '#title' => t('Display the Add another message after node creation.'),
  96. '#default_value' => variable_get('addanother_message_' . $form['#node_type']->type, FALSE),
  97. '#description' => t('Enable this checkbox if you want to show a "Add another..." message after creating a new node.'),
  98. );
  99. $form['addanother_display']['addanother_tab'] = array(
  100. '#type' => 'checkbox',
  101. '#title' => t('Display the Add another tab.'),
  102. '#default_value' => variable_get('addanother_tab_' . $form['#node_type']->type, FALSE),
  103. '#description' => t('Enable this checkbox if you want to show a "Add another" tab on nodes of this type.'),
  104. );
  105. $form['addanother_display']['addanother_tab_edit'] = array(
  106. '#type' => 'checkbox',
  107. '#title' => t('Also Display Add another tab on edit page.'),
  108. '#default_value' => variable_get('addanother_tab_edit_' . $form['#node_type']->type, FALSE),
  109. '#description' => t('Enable this checkbox if you want to also show a "Add another" tab on node edit pages of this type. Tis option does nothing if the Add Another tab is disabled.'),
  110. );
  111. }
  112. }
  113. /**
  114. * Implement hook_form_alter().
  115. */
  116. function addanother_form_alter(&$form, $form_state, $form_id) {
  117. if (!empty($form['#node_edit_form']) && empty($form['nid']['#value'])) {
  118. $node_type = $form['type']['#value'];
  119. if (user_access('use add another')) {
  120. if (variable_get('addanother_button_' . $node_type, FALSE)) {
  121. $form['actions']['addanother'] = array(
  122. '#type' => 'submit',
  123. '#value' => t('Save and add another'),
  124. '#weight' => -41,
  125. '#submit' => array('node_form_submit', 'addanother_node_form_submit')
  126. );
  127. }
  128. if (variable_get('addanother_message_' . $node_type, FALSE)) {
  129. $form['actions']['submit']['#submit'][] = 'addanother_node_form_message_submit';
  130. }
  131. }
  132. }
  133. }
  134. /**
  135. * Submit handler for the 'Save and add another' button.
  136. * This allows a redirect to be set if this was the button pressed.
  137. */
  138. function addanother_node_form_submit($form, &$form_state) {
  139. if ($node = _addanother_get_node_from_form_state($form_state)) {
  140. _addanother_quelch_message($node);
  141. theme('addanother_button_message', array('nid' => $node->nid));
  142. $form_state['redirect'] = _addanother_node_add_path($node);
  143. }
  144. }
  145. /**
  146. * Submit handler if the normal submit button was pressed, however
  147. * the node has the 'message' feature enabled.
  148. */
  149. function addanother_node_form_message_submit($form, &$form_state) {
  150. if ($node = _addanother_get_node_from_form_state($form_state)) {
  151. _addanother_quelch_message($node);
  152. theme('addanother_message_message', array('node' => $node));
  153. }
  154. }
  155. /**
  156. * Internal helper function to get the node from a $form_state
  157. */
  158. function _addanother_get_node_from_form_state(&$form_state) {
  159. // Check the node is in the form state - if it isn't, something has gone very
  160. // wrong... Best not to continue
  161. if (!isset($form_state['node'])) {
  162. return FALSE;
  163. }
  164. // Return the node
  165. return $form_state['node'];
  166. }
  167. /**
  168. * Implement hook_theme().
  169. *
  170. * Concept borrowed from 6.x Submit Again.
  171. *
  172. * @return array
  173. */
  174. function addanother_theme() {
  175. return array(
  176. 'addanother_message_message' => array(
  177. 'variables' => array('node' => NULL)
  178. ),
  179. 'addanother_button_message' => array(
  180. 'variables' => array('nid' => NULL)
  181. ),
  182. );
  183. }
  184. /**
  185. * Displays a message and link to the added/edited node after submit
  186. */
  187. function theme_addanother_message_message($variables) {
  188. $node = $variables['node'];
  189. $t_args = array(
  190. '@type' => node_type_get_name($node),
  191. '@typeurl' => url(_addanother_node_add_path($node)),
  192. '%title' => $node->title,
  193. );
  194. $addanother_message = t('@type %title has been created. You may <a href="@typeurl">add another @type</a>.', $t_args);
  195. drupal_set_message($addanother_message);
  196. return array();
  197. }
  198. /**
  199. * Displays a message and link to the added/edited node after submit
  200. */
  201. function theme_addanother_button_message($variables) {
  202. $node = node_load($variables['nid']);
  203. $t_args = array(
  204. '@type' => node_type_get_name($node),
  205. '!title' => l(drupal_placeholder($node->title), 'node/' . $node->nid, array('html' => TRUE)),
  206. );
  207. drupal_set_message(t('@type !title has been created. You may now create another.', $t_args));
  208. return array();
  209. }
  210. /**
  211. * Remove the default Drupal node creation message.
  212. */
  213. function _addanother_quelch_message($node) {
  214. if (!isset($_SESSION['messages']['status'])) return 0;
  215. $t_args = array(
  216. '@type' => node_type_get_name($node),
  217. '%title' => $node->title,
  218. );
  219. $remove[] = t('@type %title has been created.', $t_args);
  220. if ($messages = array_diff($_SESSION['messages']['status'], $remove)) {
  221. $_SESSION['messages']['status'] = $messages;
  222. }
  223. else {
  224. $_SESSION['messages']['status'] = array();
  225. }
  226. }
  227. /**
  228. * Returns node type string acceptable for URL.
  229. */
  230. function _addanother_node_type_url($type) {
  231. return str_replace('_', '-', $type);
  232. }
  233. /**
  234. * Return the best possible path to provide to the user to create another node.
  235. */
  236. function _addanother_node_add_path($node) {
  237. $path = 'node/add/' . _addanother_node_type_url($node->type);
  238. // If we are coming from a node creation path, re-use the path to save additional variables.
  239. if (arg(0) == "node" && arg(1) == "add") {
  240. $path = $_GET['q'];
  241. }
  242. return $path;
  243. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.