mb_comment.admin.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /*
  3. * @file
  4. * Function file to administer the MB Comment module settings.
  5. */
  6. /**
  7. * Provides the central MB Content settings form.
  8. */
  9. function mb_comment_admin() {
  10. $module = 'mb_comment';
  11. $mb_comment_mappings = mb_get_mappings($module);
  12. $mb_comment_values = mb_get_values($module);
  13. $form['#mappings'] = $mb_comment_mappings;
  14. foreach ($mb_comment_mappings as $type => $v) {
  15. // It makes no sense to use the MB Content module with the content type panel.
  16. if ($type == 'panel') {
  17. continue;
  18. }
  19. // Provide "Cancel" button settings.
  20. $form[$module][$type][$module . '_cancel_' . $type] = array(
  21. '#type' => 'select',
  22. '#options' => mb_cancel_button_positions(),
  23. '#default_value' => variable_get($module . '_cancel_' . $type, 0),
  24. );
  25. }
  26. $form['submit']['save'] = array(
  27. '#type' => 'submit',
  28. '#name' => 'save',
  29. '#value' => t('Save')
  30. );
  31. $form['submit']['reset'] = array(
  32. '#type' => 'submit',
  33. '#name' => 'reset',
  34. '#value' => t('Reset to defaults'),
  35. );
  36. return $form;
  37. }
  38. /**
  39. * Display a central MB Content settings form page.
  40. *
  41. * @return
  42. * The complete HTML formatted administer page.
  43. */
  44. function theme_mb_comment_admin($variables) {
  45. _mb_load_css('admin');
  46. $module = 'mb_comment';
  47. $mappings = array();
  48. $output = '';
  49. $extra_info = '';
  50. $rows = array();
  51. $form = drupal_get_form($module . '_admin');
  52. $mappings = $form['#mappings'];
  53. $output = '<h3>' . t('Comment settings') . '</h3>';
  54. $output .= '<p>' . t('Which %module functions are used by different content type pages.', array('%module' => t('More Buttons Comment'))) . '</p>';
  55. $header = array(t('Cancel'));
  56. $i = 1;
  57. foreach ($mappings as $type => $maps) {
  58. // It makes no sense to use the MB Comment module with the content type panel.
  59. if ($type == 'panel') {
  60. // Define an additional information.
  61. $extra_info .= '<p>' . t('For the content type %type no settings can be made.', array('%type' => t($mappings['panel']['name']))) . '</p>';
  62. continue;
  63. }
  64. // Convert underscores in the machine redeable type names to hyphen for right path building.
  65. $parsed_type = str_replace('_', '-', $type);
  66. // Provide own odd/even functionality.
  67. $evenodd = $i % 2 ? 'odd-mb' : 'even-mb';
  68. $evenodd = $i & 1 ? 'odd-mb' : 'even-mb';
  69. $type_link = 'admin/structure/types/manage/' . $parsed_type;
  70. $link = l($maps['name'], $type_link, array('query' => array('destination' => 'admin/config/mb/buttons/more-buttons-comment'), 'attributes' => array('title' => t('Edit this content type'))));
  71. // The content type row; Include an link to directly edit the MB Content settings in the content type.
  72. $rows[] = array('data' => array($link), 'class' => array($evenodd . ' ' . $evenodd . '-type'));
  73. // The row contains the form elements.
  74. $rows[] = array(
  75. 'data' => array(
  76. drupal_render($form[$module][$type][$module . '_cancel_' . $type])
  77. ),
  78. 'class' => array($evenodd . ' ' . $evenodd . '-elements')
  79. );
  80. unset($form[$module][$type]);
  81. ++$i;
  82. }
  83. $output .= theme('table', array(
  84. 'header' => $header,
  85. 'rows' => $rows,
  86. 'attributes' => array('class' => array('mb-admin-table', $module . '-admin-table'))
  87. ));
  88. // Display additional informations.
  89. if ($extra_info != '') {
  90. $output .= $extra_info;
  91. }
  92. $output .= drupal_render($output);
  93. $output .= drupal_render_children($form);
  94. $output .= '<p style="text-align: right">' . t('Module development by <a href="@development-url">Quiptime Group</a>.', array('@development-url' => url('http://www.quiptime.com'))) . '</p>';
  95. return $output;
  96. }
  97. /**
  98. * Save settings from admin form.
  99. */
  100. function mb_comment_admin_submit($form, &$form_state) {
  101. $module = 'mb_comment';
  102. $mappings = $form['#mappings'];
  103. if ($form_state['clicked_button']['#id'] == 'edit-save') {
  104. // Save the MB Comment button settings.
  105. foreach ($mappings as $type => $maps) {
  106. if ($type == 'panel') {
  107. continue;
  108. }
  109. variable_set($module . '_cancel_' . $type, $form_state['values'][$module . '_cancel_' . $type]);
  110. }
  111. drupal_set_message(t('The %module settings have been saved.', array('%module' => t('More Buttons Comment'))), 'status');
  112. }
  113. elseif ($form_state['clicked_button']['#id'] == 'edit-reset') {
  114. $form_state['redirect'] = 'admin/config/mb/buttons/more-buttons-comment/reset';
  115. }
  116. }
  117. /**
  118. * Menu callback to define the confirm form output.
  119. *
  120. * @return
  121. * The confirm form.
  122. */
  123. function mb_comment_reset() {
  124. $question = t('Are you sure you want to reset all %module settings?', array('%module' => t('More Buttons Comment')));
  125. $information = '<p>' . t('This action disables the settings for all buttons. This action cannot be undone.') . '</p>';
  126. return confirm_form(array(),
  127. $question,
  128. array('path' => 'admin/config/mb/buttons/more-buttons-comment', 'attributes' => array('class' => 'button')), $information,
  129. t('Reset'),
  130. t('Cancel')
  131. );
  132. }
  133. /**
  134. * Resave all system variables of the MB Content module to reset the module settings.
  135. */
  136. function mb_comment_reset_submit($form, &$form_state) {
  137. // Resave variables.
  138. $node_types = array_keys(node_type_get_types());
  139. foreach ($node_types as $type) {
  140. variable_set('mb_comment_cancel_' . $type, 0);
  141. }
  142. drupal_set_message(t('The %module settings have been set back.', array('%module' => t('More Buttons Content'))), 'status');
  143. watchdog('More Buttons Comment', 'The %module settings have been set back.', array('%module' => t('More Buttons Comment')), WATCHDOG_NOTICE, l(t('view'), 'admin/config/mb/buttons/more-buttons-comment'));
  144. $form_state['redirect'] = 'admin/config/mb/buttons/more-buttons-comment';
  145. }