source: sipes/modules_contrib/panels/plugins/export_ui/panels_layouts_ui.class.php @ de78188

stableversion-3.0
Last change on this file since de78188 was 4f375e3, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el modulo panels

  • Propiedad mode establecida a 100644
File size: 8.7 KB
Línea 
1<?php
2
3class panels_layouts_ui extends ctools_export_ui {
4  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.";
5
6  function hook_menu(&$items) {
7    // During updates, this can run before our schema is set up, so our
8    // plugin can be empty.
9    if (empty($this->plugin['menu']['items']['add'])) {
10      return;
11    }
12
13    // Change the item to a tab on the Panels page.
14    $this->plugin['menu']['items']['list callback']['type'] = MENU_LOCAL_TASK;
15
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
21    ctools_include('plugins', 'panels');
22    $this->builders = panels_get_layout_builders();
23    asort($this->builders);
24    foreach ($this->builders as $name => $builder) {
25      // Create a new menu item for the builder
26      $item = $base;
27      $item['title'] = !empty($builder['builder tab title']) ? $builder['builder tab title'] : 'Add ' . $builder['title'];
28      $item['page arguments'][] = $name;
29      $item['path'] = 'add-' . $name;
30      $this->plugin['menu']['items']['add ' . $name] = $item;
31    }
32
33    parent::hook_menu($items);
34  }
35
36  function edit_form(&$form, &$form_state) {
37    ctools_include('plugins', 'panels');
38    // If the plugin is not set, then it should be provided as an argument:
39    if (!isset($form_state['item']->plugin)) {
40      $form_state['item']->plugin = $form_state['function args'][2];
41    }
42
43    parent::edit_form($form, $form_state);
44
45    $form['category'] = array(
46      '#type' => 'textfield',
47      '#title' => t('Category'),
48      '#description' => t('What category this layout should appear in. If left blank the category will be "Miscellaneous".'),
49      '#default_value' => $form_state['item']->category,
50    );
51
52    ctools_include('context');
53    ctools_include('display-edit', 'panels');
54    ctools_include('content');
55
56    // Provide actual layout admin UI here.
57    // Create a display for editing:
58    $cache_key = 'builder-' . $form_state['item']->name;
59
60    // Load the display being edited from cache, if possible.
61    if (!empty($_POST) && is_object($cache = panels_edit_cache_get($cache_key))) {
62      $display = &$cache->display;
63    }
64    else {
65      $content_types = ctools_content_get_available_types();
66
67      panels_cache_clear('display', $cache_key);
68      $cache = new stdClass();
69
70      $display = panels_new_display();
71      $display->did = $form_state['item']->name;
72      $display->layout = $form_state['item']->plugin;
73      $display->layout_settings = $form_state['item']->settings;
74      $display->cache_key = $cache_key;
75      $display->editing_layout = TRUE;
76
77      $cache->display = $display;
78      $cache->content_types = $content_types;
79      $cache->display_title = FALSE;
80      panels_edit_cache_set($cache);
81    }
82
83    // Set up lipsum content in all of the existing panel regions:
84    $display->content = array();
85    $display->panels = array();
86    $custom = ctools_get_content_type('custom');
87    $layout = panels_get_layout($display->layout);
88
89    $regions = panels_get_regions($layout, $display);
90    foreach ($regions as $id => $title) {
91      $pane = panels_new_pane('custom', 'custom');
92      $pane->pid = $id;
93      $pane->panel = $id;
94      $pane->configuration = ctools_content_get_defaults($custom, 'custom');
95      $pane->configuration['title'] = 'Lorem Ipsum';
96      $pane->configuration['body'] = $this->lipsum;
97      $display->content[$id] = $pane;
98      $display->panels[$id] = array($id);
99    }
100
101    $form_state['display'] = &$display;
102    // Tell the Panels form not to display buttons.
103    $form_state['no buttons'] = TRUE;
104    $form_state['no display settings'] = TRUE;
105
106    $form_state['cache_key'] = $cache_key;
107    $form_state['content_types'] = $cache->content_types;
108    $form_state['display_title'] = FALSE;
109
110    $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display);
111    $form_state['renderer']->cache = &$cache;
112
113    $form = array_merge($form, panels_edit_display_form($form_state));
114    // Make sure the theme will work since our form id is different.
115    $form['#theme'] = 'panels_edit_display_form';
116
117    // If we leave the standard submit handler, it'll try to reconcile
118    // content from the input, but we've not exposed that to the user. This
119    // makes previews work with the content we forced in.
120    $form['preview']['button']['#submit'] = array('panels_edit_display_form_preview');
121  }
122
123  function edit_form_submit(&$form, &$form_state) {
124    parent::edit_form_submit($form, $form_state);
125    $form_state['item']->settings = $form_state['display']->layout_settings;
126  }
127
128  function list_form(&$form, &$form_state) {
129    ctools_include('plugins', 'panels');
130    $this->builders = panels_get_layout_builders();
131    parent::list_form($form, $form_state);
132
133    $categories = $plugins = array('all' => t('- All -'));
134    foreach ($this->items as $item) {
135      $categories[$item->category] = $item->category ? $item->category : t('Miscellaneous');
136    }
137
138    $form['top row']['category'] = array(
139      '#type' => 'select',
140      '#title' => t('Category'),
141      '#options' => $categories,
142      '#default_value' => 'all',
143      '#weight' => -10,
144    );
145
146    foreach ($this->builders as $name => $plugin) {
147      $plugins[$name] = $plugin['title'];
148    }
149
150    $form['top row']['plugin'] = array(
151      '#type' => 'select',
152      '#title' => t('Type'),
153      '#options' => $plugins,
154      '#default_value' => 'all',
155      '#weight' => -9,
156    );
157  }
158
159  function list_filter($form_state, $item) {
160    if ($form_state['values']['category'] != 'all' && $form_state['values']['category'] != $item->category) {
161      return TRUE;
162    }
163
164    if ($form_state['values']['plugin'] != 'all' && $form_state['values']['plugin'] != $item->plugin) {
165      return TRUE;
166    }
167
168    return parent::list_filter($form_state, $item);
169  }
170
171  function list_sort_options() {
172    return array(
173      'disabled' => t('Enabled, title'),
174      'title' => t('Title'),
175      'name' => t('Name'),
176      'category' => t('Category'),
177      'storage' => t('Storage'),
178      'plugin' => t('Type'),
179    );
180  }
181
182  function list_build_row($item, &$form_state, $operations) {
183    // Set up sorting
184    switch ($form_state['values']['order']) {
185      case 'disabled':
186        $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
187        break;
188      case 'title':
189        $this->sorts[$item->name] = $item->admin_title;
190        break;
191      case 'name':
192        $this->sorts[$item->name] = $item->name;
193        break;
194      case 'category':
195        $this->sorts[$item->name] = ($item->category ? $item->category : t('Miscellaneous')) . $item->admin_title;
196        break;
197      case 'plugin':
198        $this->sorts[$item->name] = $item->plugin;
199        break;
200      case 'storage':
201        $this->sorts[$item->name] = $item->type . $item->admin_title;
202        break;
203    }
204
205    $type = !empty($this->builders[$item->plugin]) ? $this->builders[$item->plugin]['title'] : t('Broken/missing plugin');
206    $category = $item->category ? check_plain($item->category) : t('Miscellaneous');
207    $this->rows[$item->name] = array(
208      'data' => array(
209        array('data' => check_plain($type), 'class' => 'ctools-export-ui-type'),
210        array('data' => check_plain($item->name), 'class' => 'ctools-export-ui-name'),
211        array('data' => check_plain($item->admin_title), 'class' => 'ctools-export-ui-title'),
212        array('data' => $category, 'class' => 'ctools-export-ui-category'),
213        array('data' => theme('links', $operations), 'class' => 'ctools-export-ui-operations'),
214      ),
215      'title' => check_plain($item->admin_description),
216      'class' => !empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled',
217    );
218  }
219
220  function list_table_header() {
221    return array(
222      array('data' => t('Type'), 'class' => 'ctools-export-ui-type'),
223      array('data' => t('Name'), 'class' => 'ctools-export-ui-name'),
224      array('data' => t('Title'), 'class' => 'ctools-export-ui-title'),
225      array('data' => t('Category'), 'class' => 'ctools-export-ui-category'),
226      array('data' => t('Operations'), 'class' => 'ctools-export-ui-operations'),
227    );
228  }
229}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.