omega_tools.wizard.inc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. /**
  3. * @todo
  4. */
  5. function omega_tools_subtheme_wizard($subtheme, $step = NULL) {
  6. ctools_include('wizard');
  7. $info = array(
  8. 'id' => 'omega_tools_subtheme_wizard',
  9. 'path' => 'admin/appearance/omega-tools/edit/' . $subtheme->machine_name . '/%step',
  10. 'free trail' => TRUE,
  11. 'show trail' => TRUE,
  12. 'show back' => TRUE,
  13. 'show cancel' => TRUE,
  14. 'show return' => FALSE,
  15. 'next text' => t('Continue'),
  16. 'next callback' => 'omega_tools_subtheme_wizard_next',
  17. 'finish callback' => 'omega_tools_subtheme_wizard_finish',
  18. 'cancel callback' => 'omega_tools_subtheme_wizard_cancel',
  19. 'finish text' => t('Finish'),
  20. 'order' => array(
  21. 'info' => t('Step 1: Theme information'),
  22. 'finalize' => t('Step 2: Finalize'),
  23. ),
  24. 'forms' => array(
  25. 'info' => array(
  26. 'form id' => 'omega_tools_subtheme_wizard_info_form',
  27. ),
  28. 'finalize' => array(
  29. 'form id' => 'omega_tools_subtheme_wizard_finalize_form',
  30. ),
  31. 'finished' => array(
  32. 'form id' => 'omega_tools_subtheme_wizard_finished_form',
  33. ),
  34. ),
  35. );
  36. $form_state = array('subtheme' => $subtheme);
  37. return ctools_wizard_multistep_form($info, $step, $form_state);
  38. }
  39. /**
  40. * @todo
  41. */
  42. function omega_tools_subtheme_wizard_cancel(&$form_state) {
  43. $subtheme = &$form_state['subtheme'];
  44. $form_state['redirect'] = 'admin/appearance';
  45. omega_tools_cache_clear($subtheme->machine_name);
  46. file_unmanaged_delete_recursive($subtheme->path);
  47. }
  48. /**
  49. * @todo
  50. */
  51. function omega_tools_subtheme_wizard_next(&$form_state) {
  52. omega_tools_cache_set($form_state['subtheme']->machine_name, $form_state['subtheme']);
  53. }
  54. /**
  55. * @todo
  56. */
  57. function omega_tools_subtheme_wizard_finish(&$form_state) {
  58. $subtheme = &$form_state['subtheme'];
  59. if ($subtheme->automated) {
  60. omega_tools_write_info_file($subtheme->machine_name, $subtheme->info, $subtheme->path);
  61. omega_tools_cache_clear($subtheme->machine_name);
  62. file_unmanaged_delete_recursive($subtheme->destination);
  63. omega_tools_move($subtheme->path, $subtheme->destination);
  64. if ((!$subtheme->status || !$subtheme->default) && variable_get('theme_default') == $subtheme->machine_name) {
  65. $subtheme->default = FALSE;
  66. theme_enable(array('bartik'));
  67. variable_set('theme_default', 'bartik');
  68. drupal_set_message(t('%name is now the default theme.', array('%name' => 'Bartik')));
  69. }
  70. omega_tools_subtheme_process($subtheme);
  71. }
  72. $form_state['redirect'] = $subtheme->automated ? 'admin/appearance' : 'admin/appearance/omega-tools/edit/' . $subtheme->machine_name . '/finished';
  73. drupal_set_message(t('The configuration options have been saved.'));
  74. }
  75. /**
  76. * @todo
  77. */
  78. function omega_tools_subtheme_wizard_info_form($form, &$form_state) {
  79. $subtheme = &$form_state['subtheme'];
  80. $form['info'] = array(
  81. '#type' => 'fieldset',
  82. '#title' => t('Theme information'),
  83. );
  84. $form['info']['name'] = array(
  85. '#type' => 'textfield',
  86. '#title' => t('Name'),
  87. '#description' => t('The human-readable name for this theme.'),
  88. '#default_value' => isset($subtheme->info['name']) ? $subtheme->info['name'] : '',
  89. '#size' => 30,
  90. '#required' => TRUE,
  91. );
  92. $form['info']['description'] = array(
  93. '#type' => 'textarea',
  94. '#title' => t('Description'),
  95. '#description' => t('The description that will be shown on the theme listing page.'),
  96. '#default_value' => isset($subtheme->info['description']) ? $subtheme->info['description'] : '',
  97. );
  98. $form['info']['version'] = array(
  99. '#type' => 'textfield',
  100. '#title' => t('Version'),
  101. '#description' => t('The version of this theme.'),
  102. '#default_value' => isset($subtheme->info['version']) ? $subtheme->info['version'] : '1.x',
  103. );
  104. $form['buttons']['next']['#next'] = $form_state['next'];
  105. return $form;
  106. }
  107. /**
  108. * @todo
  109. */
  110. function omega_tools_subtheme_wizard_info_form_submit($form, &$form_state) {
  111. $values = &$form_state['values'];
  112. $subtheme = &$form_state['subtheme'];
  113. $subtheme->info['name'] = $values['name'];
  114. $subtheme->info['description'] = $values['description'];
  115. $subtheme->info['version'] = $values['version'];
  116. }
  117. /**
  118. * @todo
  119. */
  120. function omega_tools_subtheme_wizard_finalize_form($form, &$form_state) {
  121. $subtheme = &$form_state['subtheme'];
  122. $form['finalize'] = array(
  123. '#type' => 'fieldset',
  124. '#title' => t('Finalize'),
  125. );
  126. $form['finalize']['description'] = array(
  127. '#type' => 'item',
  128. '#markup' => t('This is the final step for configuring your subtheme. You are now able to alter the final result by changing the <em>Advanced configuration</em>.'),
  129. );
  130. $form['finalize']['enable'] = array(
  131. '#type' => 'checkbox',
  132. '#title' => t('Enabled'),
  133. '#description' => t('Decide wether or not this theme should be enabled.'),
  134. '#default_value' => $subtheme->status,
  135. '#access' => $subtheme->automated,
  136. );
  137. $form['finalize']['default'] = array(
  138. '#type' => 'checkbox',
  139. '#title' => t('Default theme'),
  140. '#description' => t('Decide wether or not you want this theme to be your default theme.'),
  141. '#default_value' => $subtheme->default,
  142. '#access' => $subtheme->automated,
  143. '#states' => array(
  144. 'visible' => array(
  145. ':input[name="enable"]' => array('checked' => TRUE),
  146. ),
  147. ),
  148. );
  149. $form['finalize']['advanced'] = array(
  150. '#type' => 'fieldset',
  151. '#title' => t('Advanced configuration'),
  152. '#collapsible' => TRUE,
  153. '#collapsed' => TRUE,
  154. );
  155. $form['finalize']['advanced']['manipulate'] = array(
  156. '#type' => 'checkbox',
  157. '#title' => t('Manipulate the content of %file', array('%file' => $subtheme->machine_name . '.info')),
  158. '#description' => t('After enabling this option you are able to edit the textarea below.'),
  159. '#default_value' => FALSE,
  160. );
  161. $form['finalize']['advanced']['info'] = array(
  162. '#type' => 'textarea',
  163. '#title' => t('Content of %file', array('%file' => $subtheme->machine_name . '.info')),
  164. '#description' => t('Only change the content of this textarea if you know what you are doing.'),
  165. '#default_value' => omega_tools_build_info_file($subtheme->info),
  166. '#rows' => 20,
  167. '#states' => array(
  168. 'enabled' => array(
  169. ':input[name="manipulate"]' => array('checked' => TRUE),
  170. ),
  171. ),
  172. );
  173. unset($form['buttons']['next']);
  174. return $form;
  175. }
  176. /**
  177. * @todo
  178. */
  179. function omega_tools_subtheme_wizard_finalize_form_submit($form, &$form_state) {
  180. $values = $form_state['values'];
  181. $subtheme = &$form_state['subtheme'];
  182. $subtheme->info = $values['manipulate'] ? drupal_parse_info_format($values['info']) : $subtheme->info;
  183. $subtheme->status = $values['enable'];
  184. $subtheme->default = $values['enable'] && $values['default'];
  185. }
  186. /**
  187. * @todo
  188. */
  189. function omega_tools_subtheme_wizard_finished_form($form, &$form_state) {
  190. $subtheme = &$form_state['subtheme'];
  191. drupal_set_title(t('Your subtheme is ready for download'));
  192. unset($form['ctools_trail'], $form['buttons']['previous'], $form['buttons']['return']);
  193. $form['buttons']['cancel']['#value'] = t('Finish');
  194. $form['buttons']['next']['#value'] = t('Download');
  195. $form['message']['#markup'] = t('Please press <strong>Download</strong> to save the theme to your local hard disk. After the download has completed you can either <strong>upload the contained folder manually</strong> or install it by using the <strong>Drupal Update Manager</strong>.');
  196. $form['details'] = array(
  197. '#type' => 'fieldset',
  198. '#title' => t('Details'),
  199. '#collapsible' => TRUE,
  200. '#collapsed' => TRUE,
  201. );
  202. $form['details']['info'] = array(
  203. '#type' => 'textarea',
  204. '#title' => t('Content of the .info file'),
  205. '#default_value' => omega_tools_build_info_file($subtheme->info),
  206. '#disabled' => TRUE,
  207. '#rows' => 10,
  208. );
  209. return $form;
  210. }
  211. /**
  212. * @todo
  213. */
  214. function omega_tools_subtheme_wizard_finished_form_submit($form, &$form_state) {
  215. $subtheme = &$form_state['subtheme'];
  216. $temporary = 'temporary://omega-tools/' . $subtheme->name;
  217. file_unmanaged_delete_recursive($temporary);
  218. omega_tools_copy_recursive($subtheme->path, $temporary);
  219. if ($download = omega_tools_write_archive($temporary, $subtheme->name)) {
  220. file_transfer($download, omega_tools_file_download($download));
  221. }
  222. file_unmanaged_delete_recursive($temporary);
  223. }