panels_mini_ui.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <?php
  2. /**
  3. * @file
  4. */
  5. class panels_mini_ui extends ctools_export_ui {
  6. function init($plugin) {
  7. parent::init($plugin);
  8. ctools_include('context');
  9. }
  10. function list_form(&$form, &$form_state) {
  11. ctools_include('plugins', 'panels');
  12. $this->layouts = panels_get_layouts();
  13. parent::list_form($form, $form_state);
  14. $categories = $layouts = array('all' => t('- All -'));
  15. foreach ($this->items as $item) {
  16. $categories[$item->category] = $item->category ? $item->category : t('Mini panels');
  17. }
  18. $form['top row']['category'] = array(
  19. '#type' => 'select',
  20. '#title' => t('Category'),
  21. '#options' => $categories,
  22. '#default_value' => 'all',
  23. '#weight' => -10,
  24. );
  25. foreach ($this->layouts as $name => $plugin) {
  26. $layouts[$name] = $plugin['title'];
  27. }
  28. $form['top row']['layout'] = array(
  29. '#type' => 'select',
  30. '#title' => t('Layout'),
  31. '#options' => $layouts,
  32. '#default_value' => 'all',
  33. '#weight' => -9,
  34. );
  35. }
  36. function list_filter($form_state, $item) {
  37. if ($form_state['values']['category'] != 'all' && $form_state['values']['category'] != $item->category) {
  38. return TRUE;
  39. }
  40. if ($form_state['values']['layout'] != 'all' && $form_state['values']['layout'] != $item->display->layout) {
  41. return TRUE;
  42. }
  43. return parent::list_filter($form_state, $item);
  44. }
  45. function list_sort_options() {
  46. return array(
  47. 'disabled' => t('Enabled, title'),
  48. 'title' => t('Title'),
  49. 'name' => t('Name'),
  50. 'category' => t('Category'),
  51. 'storage' => t('Storage'),
  52. 'layout' => t('Layout'),
  53. );
  54. }
  55. function list_build_row($item, &$form_state, $operations) {
  56. // Set up sorting.
  57. switch ($form_state['values']['order']) {
  58. case 'disabled':
  59. $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
  60. break;
  61. case 'title':
  62. $this->sorts[$item->name] = $item->admin_title;
  63. break;
  64. case 'name':
  65. $this->sorts[$item->name] = $item->name;
  66. break;
  67. case 'category':
  68. $this->sorts[$item->name] = ($item->category ? $item->category : t('Mini panels')) . $item->admin_title;
  69. break;
  70. case 'layout':
  71. $this->sorts[$item->name] = $item->display->layout . $item->admin_title;
  72. break;
  73. case 'storage':
  74. $this->sorts[$item->name] = $item->type . $item->admin_title;
  75. break;
  76. }
  77. $layout = !empty($this->layouts[$item->display->layout]) ? $this->layouts[$item->display->layout]['title'] : t('Missing layout');
  78. $category = $item->category ? check_plain($item->category) : t('Mini panels');
  79. $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
  80. $this->rows[$item->name] = array(
  81. 'data' => array(
  82. array('data' => check_plain($item->admin_title), 'class' => array('ctools-export-ui-title')),
  83. array('data' => check_plain($item->name), 'class' => array('ctools-export-ui-name')),
  84. array('data' => $category, 'class' => array('ctools-export-ui-category')),
  85. array('data' => $layout, 'class' => array('ctools-export-ui-layout')),
  86. array('data' => $item->type, 'class' => array('ctools-export-ui-storage')),
  87. array('data' => $ops, 'class' => array('ctools-export-ui-operations')),
  88. ),
  89. 'title' => !empty($item->admin_description) ? check_plain($item->admin_description) : '',
  90. 'class' => array(!empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled'),
  91. );
  92. }
  93. function list_table_header() {
  94. return array(
  95. array('data' => t('Title'), 'class' => array('ctools-export-ui-title')),
  96. array('data' => t('Name'), 'class' => array('ctools-export-ui-name')),
  97. array('data' => t('Category'), 'class' => array('ctools-export-ui-category')),
  98. array('data' => t('Layout'), 'class' => array('ctools-export-ui-layout')),
  99. array('data' => t('Storage'), 'class' => array('ctools-export-ui-storage')),
  100. array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations')),
  101. );
  102. }
  103. function edit_form(&$form, &$form_state) {
  104. // Get the basic edit form.
  105. parent::edit_form($form, $form_state);
  106. // Set the admin title machine name length.
  107. // We need to do this because the system block name length is
  108. // limited to 32 chars.
  109. $form['info']['name']['#maxlength'] = 32;
  110. $form['info']['name']['#size'] = 34;
  111. $form['info']['name']['#description'] .= ' ' . t('The machine name length is limited to 32 characters, due to a limitation in the core block system.');
  112. $form['category'] = array(
  113. '#type' => 'textfield',
  114. '#size' => 24,
  115. '#default_value' => $form_state['item']->category,
  116. '#title' => t('Category'),
  117. '#description' => t("The category that this mini-panel will be grouped into on the Add Content form. Only upper and lower-case alphanumeric characters are allowed. If left blank, defaults to 'Mini panels'."),
  118. );
  119. $form['title']['#title'] = t('Title');
  120. $form['title']['#description'] = t('The title for this mini panel. It can be overridden in the block configuration.');
  121. }
  122. /**
  123. * Validate submission of the mini panel edit form.
  124. */
  125. function edit_form_basic_validate($form, &$form_state) {
  126. parent::edit_form_validate($form, $form_state);
  127. if (preg_match("/[^A-Za-z0-9 ]/", $form_state['values']['category'])) {
  128. form_error($form['category'], t('Categories may contain only alphanumerics or spaces.'));
  129. }
  130. }
  131. function edit_form_submit(&$form, &$form_state) {
  132. parent::edit_form_submit($form, $form_state);
  133. $form_state['item']->category = $form_state['values']['category'];
  134. }
  135. function edit_form_context(&$form, &$form_state) {
  136. ctools_include('context-admin');
  137. ctools_context_admin_includes();
  138. ctools_add_css('ruleset');
  139. $form['right'] = array(
  140. '#prefix' => '<div class="ctools-right-container">',
  141. '#suffix' => '</div>',
  142. );
  143. $form['left'] = array(
  144. '#prefix' => '<div class="ctools-left-container clearfix">',
  145. '#suffix' => '</div>',
  146. );
  147. // Set this up and we can use CTools' Export UI's built in wizard caching,
  148. // which already has callbacks for the context cache under this name.
  149. $module = 'export_ui::' . $this->plugin['name'];
  150. $name = $this->edit_cache_get_key($form_state['item'], $form_state['form type']);
  151. ctools_context_add_context_form($module, $form, $form_state, $form['right']['contexts_table'], $form_state['item'], $name);
  152. ctools_context_add_required_context_form($module, $form, $form_state, $form['left']['required_contexts_table'], $form_state['item'], $name);
  153. ctools_context_add_relationship_form($module, $form, $form_state, $form['right']['relationships_table'], $form_state['item'], $name);
  154. }
  155. function edit_form_context_submit(&$form, &$form_state) {
  156. // Prevent this from going to edit_form_submit();
  157. }
  158. function edit_form_layout(&$form, &$form_state) {
  159. ctools_include('common', 'panels');
  160. ctools_include('display-layout', 'panels');
  161. ctools_include('plugins', 'panels');
  162. // @todo -- figure out where/how to deal with this.
  163. $form_state['allowed_layouts'] = 'panels_mini';
  164. if ($form_state['op'] == 'add' && empty($form_state['item']->display)) {
  165. $form_state['item']->display = panels_new_display();
  166. }
  167. $form_state['display'] = &$form_state['item']->display;
  168. // Tell the Panels form not to display buttons.
  169. $form_state['no buttons'] = TRUE;
  170. // Change the #id of the form so the CSS applies properly.
  171. $form['#id'] = 'panels-choose-layout';
  172. $form = panels_choose_layout($form, $form_state);
  173. if ($form_state['op'] == 'edit') {
  174. $form['buttons']['next']['#value'] = t('Change');
  175. }
  176. }
  177. /**
  178. * Validate that a layout was chosen.
  179. */
  180. function edit_form_layout_validate(&$form, &$form_state) {
  181. $display = &$form_state['display'];
  182. if (empty($form_state['values']['layout'])) {
  183. form_error($form['layout'], t('You must select a layout.'));
  184. }
  185. if ($form_state['op'] == 'edit') {
  186. if ($form_state['values']['layout'] == $display->layout) {
  187. form_error($form['layout'], t('You must select a different layout if you wish to change layouts.'));
  188. }
  189. }
  190. }
  191. /**
  192. * A layout has been selected, set it up.
  193. */
  194. function edit_form_layout_submit(&$form, &$form_state) {
  195. $display = &$form_state['display'];
  196. if ($form_state['op'] == 'edit') {
  197. if ($form_state['values']['layout'] != $display->layout) {
  198. $form_state['item']->temp_layout = $form_state['values']['layout'];
  199. $form_state['clicked_button']['#next'] = 'move';
  200. }
  201. }
  202. else {
  203. $form_state['item']->display->layout = $form_state['values']['layout'];
  204. }
  205. }
  206. /**
  207. * When a layout is changed, the user is given the opportunity to move content.
  208. */
  209. function edit_form_move(&$form, &$form_state) {
  210. $form_state['display'] = &$form_state['item']->display;
  211. $form_state['layout'] = $form_state['item']->temp_layout;
  212. ctools_include('common', 'panels');
  213. ctools_include('display-layout', 'panels');
  214. ctools_include('plugins', 'panels');
  215. // Tell the Panels form not to display buttons.
  216. $form_state['no buttons'] = TRUE;
  217. // Change the #id of the form so the CSS applies properly.
  218. $form = panels_change_layout($form, $form_state);
  219. // This form is outside the normal wizard list, so we need to specify the
  220. // previous/next forms.
  221. $form['buttons']['previous']['#next'] = 'layout';
  222. $form['buttons']['next']['#next'] = 'content';
  223. }
  224. function edit_form_move_submit(&$form, &$form_state) {
  225. panels_change_layout_submit($form, $form_state);
  226. }
  227. function edit_form_content(&$form, &$form_state) {
  228. ctools_include('ajax');
  229. ctools_include('plugins', 'panels');
  230. ctools_include('display-edit', 'panels');
  231. ctools_include('context');
  232. // If we are cloning an item, we MUST have this cached for this to work,
  233. // so make sure:
  234. if ($form_state['form type'] == 'clone' && empty($form_state['item']->export_ui_item_is_cached)) {
  235. $this->edit_cache_set($form_state['item'], 'clone');
  236. }
  237. $cache = panels_edit_cache_get('panels_mini:' . $this->edit_cache_get_key($form_state['item'], $form_state['form type']));
  238. $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display);
  239. $form_state['renderer']->cache = &$cache;
  240. $form_state['display'] = &$cache->display;
  241. $form_state['content_types'] = $cache->content_types;
  242. // Tell the Panels form not to display buttons.
  243. $form_state['no buttons'] = TRUE;
  244. $form_state['display_title'] = !empty($cache->display_title);
  245. $form = panels_edit_display_form($form, $form_state);
  246. }
  247. function edit_form_content_submit(&$form, &$form_state) {
  248. panels_edit_display_form_submit($form, $form_state);
  249. $form_state['item']->display = $form_state['display'];
  250. }
  251. }