/[drupal]/contributions/modules/addanother/addanother.module
ViewVC logotype

Contents of /contributions/modules/addanother/addanother.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Fri May 29 15:26:29 2009 UTC (5 months, 4 weeks ago) by robinmonks
Branch: MAIN
CVS Tags: DRUPAL-6--1-4, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.5: +14 -8 lines
File MIME type: text/x-php
Patch #418852 (Keyz)
  Patch to improve permissions
  1) Adds an "administer add another" permission to allow finer adjustment of permissions.
  2) Changes "enable add another" permission to "use add another" to prevent confusion of terms.
  3) Many code style corrections.
1 <?php
2 // $Id: addanother.module,v 1.5 2009/02/04 14:45:56 robinmonks Exp $
3
4 /**
5 * @file
6 * Presents users with an option to create another node of the same type after a
7 * node is added.
8 */
9
10 /**
11 * Implementation of hook_help().
12 */
13 function addanother_help($path, $arg) {
14 $output = '';
15 switch ($path) {
16 case "admin/help#addanother":
17 $output = '<p>'. t("Presents users with an option to create another node of the same type after a node is added.") .'</p>';
18 return $output;
19 case 'admin/settings/addanother':
20 $output = '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_perm">use add another</a> permission will receive a message allowing them to add another content node of the same type.';
21 return '<p>'. t($output, array(
22 '@addanother_perm' => url('admin/user/permissions', array('fragment' => 'module-addanother')),
23 )) .'</p>';
24 }
25 }
26
27 /**
28 * Implementation of hook_perm().
29 */
30 function addanother_perm() {
31 return array('administer add another', 'use add another');
32 }
33
34 /**
35 * Implementation of hook_menu().
36 */
37 function addanother_menu() {
38 $items = array();
39 $items['admin/settings/addanother'] = array(
40 'title' => 'Add Another',
41 'description' => 'Modify which node types display the Add Another message.',
42 'page callback' => 'drupal_get_form',
43 'page arguments' => array('addanother_admin'),
44 'access arguments' => array('administer add another'),
45 'type' => MENU_NORMAL_ITEM,
46 );
47 return $items;
48 }
49
50 /**
51 * This function sets up the admin/settings/addanother settings page.
52 */
53 function addanother_admin() {
54 $form['addanother_nodetypes'] = array(
55 '#type' => 'checkboxes',
56 '#title' => t('Enable Add Another for these content types'),
57 '#options' => node_get_types('names'),
58 '#default_value' => variable_get('addanother_nodetypes', array()),
59 '#description' => 'An <em>Add Another</em> message will be shown after creating these content types',
60 );
61 return system_settings_form($form);
62 }
63
64 /**
65 * Implementation of hook_nodeapi().
66 */
67 function addanother_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
68 switch ($op) {
69 case 'insert':
70 if ($node->op == t('Save and create another')) {
71 // This prevents AddAnother's message from clashing with Submit Again.
72 return;
73 }
74 $allowed_nodetypes = variable_get('addanother_nodetypes', array());
75 if (user_access('use add another') && isset($allowed_nodetypes[$node->type]) && $allowed_nodetypes[$node->type]) {
76 global $_addanother_message;
77 $_addanother_message = t('Add another <a href="@typeurl">%type</a>.', array(
78 '@typeurl' => url('node/add/'. str_replace('_', '-', $node->type)),
79 '%type' => node_get_types('name', $node)
80 ));
81 }
82 break;
83 }
84 }
85
86 /**
87 * Implementation of hook_form_alter().
88 */
89 function addanother_form_alter(&$form, &$form_state, $form_id) {
90 if (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id) {
91 $form['buttons']['submit']['#submit'][] = '_addanother_message';
92 }
93 }
94 /**
95 * Display the Add Another message if set by addanother_nodeapi().
96 */
97 function _addanother_message($form, &$form_state) {
98 global $_addanother_message;
99 if (isset($_addanother_message)) {
100 drupal_set_message($_addanother_message, 'status', FALSE);
101 }
102 }

  ViewVC Help
Powered by ViewVC 1.1.2