/sites/all/modules/ctools/stylizer/plugins/export_ui/stylizer_ui.class.php

https://github.com/sirkitree/pipe · PHP · 271 lines · 200 code · 37 blank · 34 comment · 27 complexity · 504cc73c2e729312bf53c622da1c12b0 MD5 · raw file

  1. <?php
  2. // $Id$
  3. /**
  4. * UI class for Stylizer.
  5. */
  6. class stylizer_ui extends ctools_export_ui {
  7. function access($op, $item) {
  8. $access = parent::access($op, $item);
  9. if ($op == 'add' && $access && empty($this->base_types)) {
  10. // Make sure there are base styles defined.
  11. $access = FALSE;
  12. }
  13. return $access;
  14. }
  15. function list_form(&$form, &$form_state) {
  16. ctools_include('stylizer');
  17. parent::list_form($form, $form_state);
  18. $all = array('all' => t('- All -'));
  19. if (empty($this->base_types)) {
  20. // Give a warning about the missing base styles.
  21. drupal_set_message($this->plugin['strings']['message']['missing base type'], 'warning');
  22. }
  23. $types = $all;
  24. foreach ($this->base_types as $module => $info) {
  25. foreach ($info as $key => $base_type) {
  26. $types[$module . '-' . $key] = $base_type['title'];
  27. }
  28. }
  29. $form['top row']['type'] = array(
  30. '#type' => 'select',
  31. '#title' => t('Type'),
  32. '#options' => $types,
  33. '#default_value' => 'all',
  34. '#weight' => -10,
  35. '#attributes' => array('class' => 'ctools-auto-submit'),
  36. );
  37. $plugins = ctools_get_style_bases();
  38. $form_state['style_plugins'] = $plugins;
  39. $options = $all;
  40. // @todo base should use $module . '-' . $name
  41. foreach ($plugins as $name => $plugin) {
  42. $options[$name] = $plugin['title'];
  43. }
  44. $form['top row']['base'] = array(
  45. '#type' => 'select',
  46. '#title' => t('Base'),
  47. '#options' => $all + $options,
  48. '#default_value' => 'all',
  49. '#weight' => -9,
  50. '#attributes' => array('class' => 'ctools-auto-submit'),
  51. );
  52. }
  53. function list_sort_options() {
  54. return array(
  55. 'disabled' => t('Enabled, title'),
  56. 'title' => t('Title'),
  57. 'name' => t('Name'),
  58. 'base' => t('Base'),
  59. 'type' => t('Type'),
  60. 'storage' => t('Storage'),
  61. );
  62. }
  63. function list_filter($form_state, $item) {
  64. if (empty($form_state['style_plugins'][$item->settings['style_base']])) {
  65. $this->style_plugin = array(
  66. 'name' => 'broken',
  67. 'title' => t('Missing plugin'),
  68. 'type' => t('Unknown'),
  69. 'module' => '',
  70. );
  71. }
  72. else {
  73. $this->style_plugin = $form_state['style_plugins'][$item->settings['style_base']];
  74. }
  75. // This isn't really a field, but by setting this we can list it in the
  76. // filter fields and have the search box pick it up.
  77. $item->plugin_title = $this->style_plugin['title'];
  78. if ($form_state['values']['type'] != 'all') {
  79. list($module, $type) = explode('-', $form_state['values']['type']);
  80. if ($module != $this->style_plugin['module'] || $type != $this->style_plugin['type']) {
  81. return TRUE;
  82. }
  83. }
  84. if ($form_state['values']['base'] != 'all' && $form_state['values']['base'] != $this->style_plugin['name']) {
  85. return TRUE;
  86. }
  87. return parent::list_filter($form_state, $item);
  88. }
  89. function list_search_fields() {
  90. $fields = parent::list_search_fields();
  91. $fields[] = 'plugin_title';
  92. return $fields;
  93. }
  94. function list_build_row($item, &$form_state, $operations) {
  95. // Set up sorting
  96. switch ($form_state['values']['order']) {
  97. case 'disabled':
  98. $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
  99. break;
  100. case 'title':
  101. $this->sorts[$item->name] = $item->admin_title;
  102. break;
  103. case 'name':
  104. $this->sorts[$item->name] = $item->name;
  105. break;
  106. case 'type':
  107. $this->sorts[$item->name] = $this->style_plugin['type'] . $item->admin_title;
  108. break;
  109. case 'base':
  110. $this->sorts[$item->name] = $this->style_plugin['title'] . $item->admin_title;
  111. break;
  112. case 'storage':
  113. $this->sorts[$item->name] = $item->type . $item->admin_title;
  114. break;
  115. }
  116. if (!empty($this->base_types[$this->style_plugin['module']][$this->style_plugin['type']])) {
  117. $type = $this->base_types[$this->style_plugin['module']][$this->style_plugin['type']]['title'];
  118. }
  119. else {
  120. $type = t('Unknown');
  121. }
  122. $this->rows[$item->name] = array(
  123. 'data' => array(
  124. array('data' => $type, 'class' => 'ctools-export-ui-type'),
  125. array('data' => check_plain($item->name), 'class' => 'ctools-export-ui-name'),
  126. array('data' => check_plain($item->admin_title), 'class' => 'ctools-export-ui-title'),
  127. array('data' => check_plain($this->style_plugin['title']), 'class' => 'ctools-export-ui-base'),
  128. array('data' => check_plain($item->type), 'class' => 'ctools-export-ui-storage'),
  129. array('data' => theme('links', $operations), 'class' => 'ctools-export-ui-operations'),
  130. ),
  131. 'title' => check_plain($item->admin_description),
  132. 'class' => !empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled',
  133. );
  134. }
  135. function list_table_header() {
  136. return array(
  137. array('data' => t('Type'), 'class' => 'ctools-export-ui-type'),
  138. array('data' => t('Name'), 'class' => 'ctools-export-ui-name'),
  139. array('data' => t('Title'), 'class' => 'ctools-export-ui-title'),
  140. array('data' => t('Base'), 'class' => 'ctools-export-ui-base'),
  141. array('data' => t('Storage'), 'class' => 'ctools-export-ui-storage'),
  142. array('data' => t('Operations'), 'class' => 'ctools-export-ui-operations'),
  143. );
  144. }
  145. function init($plugin) {
  146. ctools_include('stylizer');
  147. $this->base_types = ctools_get_style_base_types();
  148. parent::init($plugin);
  149. }
  150. function get_wizard_info(&$form_state) {
  151. $form_info = parent::get_wizard_info($form_state);
  152. ctools_include('stylizer');
  153. // For add forms, we have temporarily set the 'form type' to include
  154. // the style type so the default wizard_info can find the path. If
  155. // we did that, we have to put it back.
  156. if (!empty($form_state['type'])) {
  157. $form_state['form type'] = 'add';
  158. $form_info['show back'] = TRUE;
  159. }
  160. // Ensure these do not get out of sync.
  161. $form_state['item']->settings['name'] = $form_state['item']->name;
  162. $form_state['settings'] = $form_state['item']->settings;
  163. // Figure out the base style plugin in use and make sure that is available.
  164. $plugin = NULL;
  165. if (!empty($form_state['item']->settings['style_base'])) {
  166. $plugin = ctools_get_style_base($form_state['item']->settings['style_base']);
  167. ctools_stylizer_add_plugin_forms($form_info, $plugin, $form_state['op']);
  168. }
  169. else {
  170. // This is here so the 'finish' button does not show up, and because
  171. // we don't have the selected style we don't know what the next form(s)
  172. // will be.
  173. $form_info['order']['next'] = t('Configure style');
  174. }
  175. // If available, make sure these are available for the 'choose' form.
  176. if (!empty($form_state['item']->style_module)) {
  177. $form_state['module'] = $form_state['item']->style_module;
  178. $form_state['type'] = $form_state['item']->style_type;
  179. }
  180. $form_state['plugin'] = $plugin;
  181. $form_state['settings'] = $form_state['item']->settings;
  182. return $form_info;
  183. }
  184. /**
  185. * Store the stylizer info in our settings.
  186. *
  187. * The stylizer wizard stores its stuff in slightly different places, so
  188. * we have to find it and move it to the right place.
  189. */
  190. function store_stylizer_info(&$form_state) {
  191. /*
  192. foreach (array('name', 'admin_title', 'admin_description') as $key) {
  193. if (!empty($form_state['values'][$key])) {
  194. $form_state['item']->{$key} = $form_state['values'][$key];
  195. }
  196. }
  197. */
  198. if ($form_state['step'] != 'import') {
  199. $form_state['item']->settings = $form_state['settings'];
  200. }
  201. // Do not let the 'name' accidentally get out of sync under any circumstances.
  202. $form_state['item']->settings['name'] = $form_state['item']->name;
  203. }
  204. function edit_wizard_next(&$form_state) {
  205. $this->store_stylizer_info($form_state);
  206. parent::edit_wizard_next($form_state);
  207. }
  208. function edit_wizard_finish(&$form_state) {
  209. // These might be stored by the stylizer wizard, so we should clear them.
  210. if (isset($form_state['settings']['old_settings'])) {
  211. unset($form_state['settings']['old_settings']);
  212. }
  213. $this->store_stylizer_info($form_state);
  214. parent::edit_wizard_finish($form_state);
  215. }
  216. function edit_form_type(&$form, &$form_state) {
  217. foreach ($this->base_types as $module => $info) {
  218. foreach ($info as $key => $base_type) {
  219. $types[$module . '-' . $key] = $base_type['title'];
  220. }
  221. }
  222. $form['type'] = array(
  223. '#type' => 'select',
  224. '#title' => t('Type'),
  225. '#options' => $types,
  226. '#default_value' => 'all',
  227. '#weight' => -10,
  228. '#attributes' => array('class' => 'ctools-auto-submit'),
  229. );
  230. }
  231. function edit_form_type_submit(&$form, &$form_state) {
  232. list($form_state['item']->style_module, $form_state['item']->style_type) = explode('-', $form_state['values']['type']);
  233. }
  234. }