Projet

Général

Profil

Paste
Télécharger (9,21 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panels / plugins / export_ui / panels_layouts_ui.class.php @ 27945136

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