Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains the administrative UI for reusable layouts.
6
 */
7
class panels_layouts_ui extends ctools_export_ui {
8
  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.";
9

    
10
  function hook_menu(&$items) {
11
    // During updates, this can run before our schema is set up, so our
12
    // plugin can be empty.
13
    if (empty($this->plugin['menu']['items']['add'])) {
14
      return;
15
    }
16

    
17
    // Change the item to a tab on the Panels page.
18
    $this->plugin['menu']['items']['list callback']['type'] = MENU_LOCAL_TASK;
19

    
20
    // Establish a base for adding plugins.
21
    $base = $this->plugin['menu']['items']['add'];
22
    // Remove the default 'add' menu item.
23
    unset($this->plugin['menu']['items']['add']);
24

    
25
    ctools_include('plugins', 'panels');
26
    $this->builders = panels_get_layout_builders();
27
    asort($this->builders);
28
    foreach ($this->builders as $name => $builder) {
29
      // Create a new menu item for the builder.
30
      $item = $base;
31
      $item['title'] = !empty($builder['builder tab title']) ? $builder['builder tab title'] : 'Add ' . $builder['title'];
32
      $item['page arguments'][] = $name;
33
      $item['path'] = 'add-' . $name;
34
      $this->plugin['menu']['items']['add ' . $name] = $item;
35
    }
36

    
37
    parent::hook_menu($items);
38
  }
39

    
40
  function edit_form(&$form, &$form_state) {
41
    ctools_include('plugins', 'panels');
42
    // If the plugin is not set, then it should be provided as an argument:
43
    if (!isset($form_state['item']->plugin)) {
44
      $form_state['item']->plugin = $form_state['function args'][2];
45
    }
46

    
47
    parent::edit_form($form, $form_state);
48

    
49
    $form['category'] = array(
50
      '#type' => 'textfield',
51
      '#title' => t('Category'),
52
      '#description' => t('What category this layout should appear in. If left blank the category will be "Miscellaneous".'),
53
      '#default_value' => $form_state['item']->category,
54
    );
55

    
56
    ctools_include('context');
57
    ctools_include('display-edit', 'panels');
58
    ctools_include('content');
59

    
60
    // Provide actual layout admin UI here.
61
    // Create a display for editing:
62
    $cache_key = 'builder-' . $form_state['item']->name;
63

    
64
    // Load the display being edited from cache, if possible.
65
    if (!empty($_POST) && is_object($cache = panels_edit_cache_get($cache_key))) {
66
      $display = &$cache->display;
67
    }
68
    else {
69
      $content_types = ctools_content_get_available_types();
70

    
71
      panels_cache_clear('display', $cache_key);
72
      $cache = new stdClass();
73

    
74
      $display = panels_new_display();
75
      $display->did = $form_state['item']->name;
76
      $display->layout = $form_state['item']->plugin;
77
      $display->layout_settings = $form_state['item']->settings;
78
      $display->cache_key = $cache_key;
79
      $display->editing_layout = TRUE;
80
      $display->storage_type = 'panels_layouts_ui';
81
      $display->storage_id = 'panels_layouts_ui';
82

    
83
      $cache->display = $display;
84
      $cache->content_types = $content_types;
85
      $cache->display_title = FALSE;
86
      panels_edit_cache_set($cache);
87
    }
88

    
89
    // Set up lipsum content in all of the existing panel regions:
90
    $display->content = array();
91
    $display->panels = array();
92
    $custom = ctools_get_content_type('custom');
93
    $layout = panels_get_layout($display->layout);
94

    
95
    $regions = panels_get_regions($layout, $display);
96
    foreach ($regions as $id => $title) {
97
      $pane = panels_new_pane('custom', 'custom');
98
      $pane->pid = $id;
99
      $pane->panel = $id;
100
      $pane->configuration = ctools_content_get_defaults($custom, 'custom');
101
      $pane->configuration['title'] = 'Lorem Ipsum';
102
      $pane->configuration['body'] = $this->lipsum;
103
      $display->content[$id] = $pane;
104
      $display->panels[$id] = array($id);
105
    }
106

    
107
    $form_state['display'] = &$display;
108
    // Tell the Panels form not to display buttons.
109
    $form_state['no buttons'] = TRUE;
110
    $form_state['no display settings'] = TRUE;
111

    
112
    $form_state['cache_key'] = $cache_key;
113
    $form_state['content_types'] = $cache->content_types;
114
    $form_state['display_title'] = FALSE;
115

    
116
    $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display);
117
    $form_state['renderer']->cache = &$cache;
118

    
119
    $form = panels_edit_display_form($form, $form_state);
120

    
121
    // If we leave the standard submit handler, it'll try to reconcile
122
    // content from the input, but we've not exposed that to the user. This
123
    // makes previews work with the content we forced in.
124
    $form['preview']['button']['#submit'] = array('panels_edit_display_form_preview');
125
  }
126

    
127
  function edit_form_submit(&$form, &$form_state) {
128
    parent::edit_form_submit($form, $form_state);
129

    
130
    // While we short circuited the main submit hook, we need to keep this one.
131
    panels_edit_display_settings_form_submit($form, $form_state);
132
    $form_state['item']->settings = $form_state['display']->layout_settings;
133
  }
134

    
135
  function edit_form_validate(&$form, &$form_state) {
136
    parent::edit_form_validate($form, $form_state);
137

    
138
    // While we short circuited the main validate hook, we need to keep this one.
139
    panels_edit_display_settings_form_validate($form, $form_state);
140
  }
141

    
142
  function list_form(&$form, &$form_state) {
143
    ctools_include('plugins', 'panels');
144
    $this->builders = panels_get_layout_builders();
145
    parent::list_form($form, $form_state);
146

    
147
    $categories = $plugins = array('all' => t('- All -'));
148
    foreach ($this->items as $item) {
149
      $categories[$item->category] = $item->category ? $item->category : t('Miscellaneous');
150
    }
151

    
152
    $form['top row']['category'] = array(
153
      '#type' => 'select',
154
      '#title' => t('Category'),
155
      '#options' => $categories,
156
      '#default_value' => 'all',
157
      '#weight' => -10,
158
    );
159

    
160
    foreach ($this->builders as $name => $plugin) {
161
      $plugins[$name] = $plugin['title'];
162
    }
163

    
164
    $form['top row']['plugin'] = array(
165
      '#type' => 'select',
166
      '#title' => t('Type'),
167
      '#options' => $plugins,
168
      '#default_value' => 'all',
169
      '#weight' => -9,
170
    );
171
  }
172

    
173
  function list_filter($form_state, $item) {
174
    if ($form_state['values']['category'] != 'all' && $form_state['values']['category'] != $item->category) {
175
      return TRUE;
176
    }
177

    
178
    if ($form_state['values']['plugin'] != 'all' && $form_state['values']['plugin'] != $item->plugin) {
179
      return TRUE;
180
    }
181

    
182
    return parent::list_filter($form_state, $item);
183
  }
184

    
185
  function list_sort_options() {
186
    return array(
187
      'disabled' => t('Enabled, title'),
188
      'title' => t('Title'),
189
      'name' => t('Name'),
190
      'category' => t('Category'),
191
      'storage' => t('Storage'),
192
      'plugin' => t('Type'),
193
    );
194
  }
195

    
196
  function list_build_row($item, &$form_state, $operations) {
197
    // Set up sorting.
198
    switch ($form_state['values']['order']) {
199
      case 'disabled':
200
        $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
201
        break;
202

    
203
      case 'title':
204
        $this->sorts[$item->name] = $item->admin_title;
205
        break;
206

    
207
      case 'name':
208
        $this->sorts[$item->name] = $item->name;
209
        break;
210

    
211
      case 'category':
212
        $this->sorts[$item->name] = ($item->category ? $item->category : t('Miscellaneous')) . $item->admin_title;
213
        break;
214

    
215
      case 'plugin':
216
        $this->sorts[$item->name] = $item->plugin;
217
        break;
218

    
219
      case 'storage':
220
        $this->sorts[$item->name] = $item->type . $item->admin_title;
221
        break;
222
    }
223

    
224
    $type = !empty($this->builders[$item->plugin]) ? $this->builders[$item->plugin]['title'] : t('Broken/missing plugin');
225
    $category = $item->category ? check_plain($item->category) : t('Miscellaneous');
226

    
227
    $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
228

    
229
    $this->rows[$item->name] = array(
230
      'data' => array(
231
        array('data' => check_plain($type), 'class' => array('ctools-export-ui-type')),
232
        array('data' => check_plain($item->name), 'class' => array('ctools-export-ui-name')),
233
        array('data' => check_plain($item->admin_title), 'class' => array('ctools-export-ui-title')),
234
        array('data' => $category, 'class' => array('ctools-export-ui-category')),
235
        array('data' => $ops, 'class' => array('ctools-export-ui-operations')),
236
      ),
237
      'title' => check_plain($item->admin_description),
238
      'class' => array(!empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled'),
239
    );
240
  }
241

    
242
  function list_table_header() {
243
    return array(
244
      array('data' => t('Type'), 'class' => array('ctools-export-ui-type')),
245
      array('data' => t('Name'), 'class' => array('ctools-export-ui-name')),
246
      array('data' => t('Title'), 'class' => array('ctools-export-ui-title')),
247
      array('data' => t('Category'), 'class' => array('ctools-export-ui-category')),
248
      array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations')),
249
    );
250
  }
251

    
252
}