mb_content.admin.inc 6.6 KB

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