PageRenderTime 36ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/sites/all/modules/panels/plugins/export_ui/panels_layouts_ui.class.php

https://gitlab.com/manuvelasco/agostoliquida
PHP | 245 lines | 182 code | 41 blank | 22 comment | 14 complexity | 29fb6e98a17829714f2691688b866ccb MD5 | raw file
  1. <?php
  2. /**
  3. * @file
  4. * Contains the administrative UI for reusable layouts.
  5. */
  6. class panels_layouts_ui extends ctools_export_ui {
  7. var $lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam egestas congue nibh, vel dictum ante posuere vitae. Cras gravida massa tempor metus eleifend sed elementum tortor scelerisque. Vivamus egestas, tortor quis luctus tristique, sem velit adipiscing risus, et tempus enim felis in massa. Morbi viverra, nisl quis rhoncus imperdiet, turpis massa vestibulum turpis, egestas faucibus nibh metus vel nunc. In hac habitasse platea dictumst. Nunc sit amet nisi quis ipsum tincidunt semper. Donec ac urna enim, et placerat arcu. Morbi eu laoreet justo. Nullam nec velit eu neque mattis pulvinar sed non libero. Sed sed vulputate erat. Fusce sit amet dui nibh.";
  8. function hook_menu(&$items) {
  9. // During updates, this can run before our schema is set up, so our
  10. // plugin can be empty.
  11. if (empty($this->plugin['menu']['items']['add'])) {
  12. return;
  13. }
  14. // Change the item to a tab on the Panels page.
  15. $this->plugin['menu']['items']['list callback']['type'] = MENU_LOCAL_TASK;
  16. // Establish a base for adding plugins
  17. $base = $this->plugin['menu']['items']['add'];
  18. // Remove the default 'add' menu item.
  19. unset($this->plugin['menu']['items']['add']);
  20. ctools_include('plugins', 'panels');
  21. $this->builders = panels_get_layout_builders();
  22. asort($this->builders);
  23. foreach ($this->builders as $name => $builder) {
  24. // Create a new menu item for the builder
  25. $item = $base;
  26. $item['title'] = !empty($builder['builder tab title']) ? $builder['builder tab title'] : 'Add ' . $builder['title'];
  27. $item['page arguments'][] = $name;
  28. $item['path'] = 'add-' . $name;
  29. $this->plugin['menu']['items']['add ' . $name] = $item;
  30. }
  31. parent::hook_menu($items);
  32. }
  33. function edit_form(&$form, &$form_state) {
  34. ctools_include('plugins', 'panels');
  35. // If the plugin is not set, then it should be provided as an argument:
  36. if (!isset($form_state['item']->plugin)) {
  37. $form_state['item']->plugin = $form_state['function args'][2];
  38. }
  39. parent::edit_form($form, $form_state);
  40. $form['category'] = array(
  41. '#type' => 'textfield',
  42. '#title' => t('Category'),
  43. '#description' => t('What category this layout should appear in. If left blank the category will be "Miscellaneous".'),
  44. '#default_value' => $form_state['item']->category,
  45. );
  46. ctools_include('context');
  47. ctools_include('display-edit', 'panels');
  48. ctools_include('content');
  49. // Provide actual layout admin UI here.
  50. // Create a display for editing:
  51. $cache_key = 'builder-' . $form_state['item']->name;
  52. // Load the display being edited from cache, if possible.
  53. if (!empty($_POST) && is_object($cache = panels_edit_cache_get($cache_key))) {
  54. $display = &$cache->display;
  55. }
  56. else {
  57. $content_types = ctools_content_get_available_types();
  58. panels_cache_clear('display', $cache_key);
  59. $cache = new stdClass();
  60. $display = panels_new_display();
  61. $display->did = $form_state['item']->name;
  62. $display->layout = $form_state['item']->plugin;
  63. $display->layout_settings = $form_state['item']->settings;
  64. $display->cache_key = $cache_key;
  65. $display->editing_layout = TRUE;
  66. $cache->display = $display;
  67. $cache->content_types = $content_types;
  68. $cache->display_title = FALSE;
  69. panels_edit_cache_set($cache);
  70. }
  71. // Set up lipsum content in all of the existing panel regions:
  72. $display->content = array();
  73. $display->panels = array();
  74. $custom = ctools_get_content_type('custom');
  75. $layout = panels_get_layout($display->layout);
  76. $regions = panels_get_regions($layout, $display);
  77. foreach ($regions as $id => $title) {
  78. $pane = panels_new_pane('custom', 'custom');
  79. $pane->pid = $id;
  80. $pane->panel = $id;
  81. $pane->configuration = ctools_content_get_defaults($custom, 'custom');
  82. $pane->configuration['title'] = 'Lorem Ipsum';
  83. $pane->configuration['body'] = $this->lipsum;
  84. $display->content[$id] = $pane;
  85. $display->panels[$id] = array($id);
  86. }
  87. $form_state['display'] = &$display;
  88. // Tell the Panels form not to display buttons.
  89. $form_state['no buttons'] = TRUE;
  90. $form_state['no display settings'] = TRUE;
  91. $form_state['cache_key'] = $cache_key;
  92. $form_state['content_types'] = $cache->content_types;
  93. $form_state['display_title'] = FALSE;
  94. $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display);
  95. $form_state['renderer']->cache = &$cache;
  96. $form = panels_edit_display_form($form, $form_state);
  97. // If we leave the standard submit handler, it'll try to reconcile
  98. // content from the input, but we've not exposed that to the user. This
  99. // makes previews work with the content we forced in.
  100. $form['preview']['button']['#submit'] = array('panels_edit_display_form_preview');
  101. }
  102. function edit_form_submit(&$form, &$form_state) {
  103. parent::edit_form_submit($form, $form_state);
  104. // While we short circuited the main submit hook, we need to keep this one.
  105. panels_edit_display_settings_form_submit($form, $form_state);
  106. $form_state['item']->settings = $form_state['display']->layout_settings;
  107. }
  108. function edit_form_validate(&$form, &$form_state) {
  109. parent::edit_form_validate($form, $form_state);
  110. // While we short circuited the main validate hook, we need to keep this one.
  111. panels_edit_display_settings_form_validate($form, $form_state);
  112. }
  113. function list_form(&$form, &$form_state) {
  114. ctools_include('plugins', 'panels');
  115. $this->builders = panels_get_layout_builders();
  116. parent::list_form($form, $form_state);
  117. $categories = $plugins = array('all' => t('- All -'));
  118. foreach ($this->items as $item) {
  119. $categories[$item->category] = $item->category ? $item->category : t('Miscellaneous');
  120. }
  121. $form['top row']['category'] = array(
  122. '#type' => 'select',
  123. '#title' => t('Category'),
  124. '#options' => $categories,
  125. '#default_value' => 'all',
  126. '#weight' => -10,
  127. );
  128. foreach ($this->builders as $name => $plugin) {
  129. $plugins[$name] = $plugin['title'];
  130. }
  131. $form['top row']['plugin'] = array(
  132. '#type' => 'select',
  133. '#title' => t('Type'),
  134. '#options' => $plugins,
  135. '#default_value' => 'all',
  136. '#weight' => -9,
  137. );
  138. }
  139. function list_filter($form_state, $item) {
  140. if ($form_state['values']['category'] != 'all' && $form_state['values']['category'] != $item->category) {
  141. return TRUE;
  142. }
  143. if ($form_state['values']['plugin'] != 'all' && $form_state['values']['plugin'] != $item->plugin) {
  144. return TRUE;
  145. }
  146. return parent::list_filter($form_state, $item);
  147. }
  148. function list_sort_options() {
  149. return array(
  150. 'disabled' => t('Enabled, title'),
  151. 'title' => t('Title'),
  152. 'name' => t('Name'),
  153. 'category' => t('Category'),
  154. 'storage' => t('Storage'),
  155. 'plugin' => t('Type'),
  156. );
  157. }
  158. function list_build_row($item, &$form_state, $operations) {
  159. // Set up sorting
  160. switch ($form_state['values']['order']) {
  161. case 'disabled':
  162. $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
  163. break;
  164. case 'title':
  165. $this->sorts[$item->name] = $item->admin_title;
  166. break;
  167. case 'name':
  168. $this->sorts[$item->name] = $item->name;
  169. break;
  170. case 'category':
  171. $this->sorts[$item->name] = ($item->category ? $item->category : t('Miscellaneous')) . $item->admin_title;
  172. break;
  173. case 'plugin':
  174. $this->sorts[$item->name] = $item->plugin;
  175. break;
  176. case 'storage':
  177. $this->sorts[$item->name] = $item->type . $item->admin_title;
  178. break;
  179. }
  180. $type = !empty($this->builders[$item->plugin]) ? $this->builders[$item->plugin]['title'] : t('Broken/missing plugin');
  181. $category = $item->category ? check_plain($item->category) : t('Miscellaneous');
  182. $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
  183. $this->rows[$item->name] = array(
  184. 'data' => array(
  185. array('data' => check_plain($type), 'class' => array('ctools-export-ui-type')),
  186. array('data' => check_plain($item->name), 'class' => array('ctools-export-ui-name')),
  187. array('data' => check_plain($item->admin_title), 'class' => array('ctools-export-ui-title')),
  188. array('data' => $category, 'class' => array('ctools-export-ui-category')),
  189. array('data' => $ops, 'class' => array('ctools-export-ui-operations')),
  190. ),
  191. 'title' => check_plain($item->admin_description),
  192. 'class' => array(!empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled'),
  193. );
  194. }
  195. function list_table_header() {
  196. return array(
  197. array('data' => t('Type'), 'class' => array('ctools-export-ui-type')),
  198. array('data' => t('Name'), 'class' => array('ctools-export-ui-name')),
  199. array('data' => t('Title'), 'class' => array('ctools-export-ui-title')),
  200. array('data' => t('Category'), 'class' => array('ctools-export-ui-category')),
  201. array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations')),
  202. );
  203. }
  204. }