Projet

Général

Profil

Paste
Télécharger (10,8 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panels / panels_mini / plugins / export_ui / panels_mini_ui.class.php @ 5a7e6170

1
<?php
2

    
3
class panels_mini_ui extends ctools_export_ui {
4
  function init($plugin) {
5
    parent::init($plugin);
6
    ctools_include('context');
7
  }
8

    
9
  function list_form(&$form, &$form_state) {
10
    ctools_include('plugins', 'panels');
11
    $this->layouts = panels_get_layouts();
12

    
13
    parent::list_form($form, $form_state);
14

    
15
    $categories = $layouts = array('all' => t('- All -'));
16
    foreach ($this->items as $item) {
17
      $categories[$item->category] = $item->category ? $item->category : t('Mini panels');
18
    }
19

    
20
    $form['top row']['category'] = array(
21
      '#type' => 'select',
22
      '#title' => t('Category'),
23
      '#options' => $categories,
24
      '#default_value' => 'all',
25
      '#weight' => -10,
26
    );
27

    
28
    foreach ($this->layouts as $name => $plugin) {
29
      $layouts[$name] = $plugin['title'];
30
    }
31

    
32
    $form['top row']['layout'] = array(
33
      '#type' => 'select',
34
      '#title' => t('Layout'),
35
      '#options' => $layouts,
36
      '#default_value' => 'all',
37
      '#weight' => -9,
38
    );
39
  }
40

    
41
  function list_filter($form_state, $item) {
42
    if ($form_state['values']['category'] != 'all' && $form_state['values']['category'] != $item->category) {
43
      return TRUE;
44
    }
45

    
46
    if ($form_state['values']['layout'] != 'all' && $form_state['values']['layout'] != $item->display->layout) {
47
      return TRUE;
48
    }
49

    
50
    return parent::list_filter($form_state, $item);
51
  }
52

    
53
  function list_sort_options() {
54
    return array(
55
      'disabled' => t('Enabled, title'),
56
      'title' => t('Title'),
57
      'name' => t('Name'),
58
      'category' => t('Category'),
59
      'storage' => t('Storage'),
60
      'layout' => t('Layout'),
61
    );
62
  }
63

    
64
  function list_build_row($item, &$form_state, $operations) {
65
    // Set up sorting
66
    switch ($form_state['values']['order']) {
67
      case 'disabled':
68
        $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
69
        break;
70
      case 'title':
71
        $this->sorts[$item->name] = $item->admin_title;
72
        break;
73
      case 'name':
74
        $this->sorts[$item->name] = $item->name;
75
        break;
76
      case 'category':
77
        $this->sorts[$item->name] = ($item->category ? $item->category : t('Mini panels')) . $item->admin_title;
78
        break;
79
      case 'layout':
80
        $this->sorts[$item->name] = $item->display->layout . $item->admin_title;
81
        break;
82
      case 'storage':
83
        $this->sorts[$item->name] = $item->type . $item->admin_title;
84
        break;
85
    }
86

    
87
    $layout = !empty($this->layouts[$item->display->layout]) ? $this->layouts[$item->display->layout]['title'] : t('Missing layout');
88
    $category = $item->category ? check_plain($item->category) : t('Mini panels');
89

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

    
92
    $this->rows[$item->name] = array(
93
      'data' => array(
94
        array('data' => check_plain($item->admin_title), 'class' => array('ctools-export-ui-title')),
95
        array('data' => check_plain($item->name), 'class' => array('ctools-export-ui-name')),
96
        array('data' => $category, 'class' => array('ctools-export-ui-category')),
97
        array('data' => $layout, 'class' => array('ctools-export-ui-layout')),
98
        array('data' => $item->type, 'class' => array('ctools-export-ui-storage')),
99
        array('data' => $ops, 'class' => array('ctools-export-ui-operations')),
100
      ),
101
      'title' => !empty($item->admin_description) ? check_plain($item->admin_description) : '',
102
      'class' => array(!empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled'),
103
    );
104
  }
105

    
106
  function list_table_header() {
107
    return array(
108
      array('data' => t('Title'), 'class' => array('ctools-export-ui-title')),
109
      array('data' => t('Name'), 'class' => array('ctools-export-ui-name')),
110
      array('data' => t('Category'), 'class' => array('ctools-export-ui-category')),
111
      array('data' => t('Layout'), 'class' => array('ctools-export-ui-layout')),
112
      array('data' => t('Storage'), 'class' => array('ctools-export-ui-storage')),
113
      array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations')),
114
    );
115
  }
116

    
117
  function edit_form(&$form, &$form_state) {
118
    // Get the basic edit form
119
    parent::edit_form($form, $form_state);
120

    
121
    // Set the admin title machine name length.
122
    // We need to do this because the system block name length is
123
    // limited to 32 chars.
124
    $form['info']['name']['#maxlength'] = 32;
125
    $form['info']['name']['#size'] = 34;
126
    $form['info']['name']['#description'] .= ' ' . t('The machine name length is limited to 32 characters, due to a limitation in the core block system.');
127

    
128
    $form['category'] = array(
129
      '#type' => 'textfield',
130
      '#size' => 24,
131
      '#default_value' => $form_state['item']->category,
132
      '#title' => t('Category'),
133
      '#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'."),
134
    );
135

    
136
    $form['title']['#title'] = t('Title');
137
    $form['title']['#description'] = t('The title for this mini panel. It can be overridden in the block configuration.');
138
  }
139

    
140
  /**
141
   * Validate submission of the mini panel edit form.
142
   */
143
  function edit_form_basic_validate($form, &$form_state) {
144
    parent::edit_form_validate($form, $form_state);
145
    if (preg_match("/[^A-Za-z0-9 ]/", $form_state['values']['category'])) {
146
      form_error($form['category'], t('Categories may contain only alphanumerics or spaces.'));
147
    }
148
  }
149

    
150
  function edit_form_submit(&$form, &$form_state) {
151
    parent::edit_form_submit($form, $form_state);
152
    $form_state['item']->category = $form_state['values']['category'];
153
  }
154

    
155
  function edit_form_context(&$form, &$form_state) {
156
    ctools_include('context-admin');
157
    ctools_context_admin_includes();
158
    ctools_add_css('ruleset');
159

    
160
    $form['right'] = array(
161
      '#prefix' => '<div class="ctools-right-container">',
162
      '#suffix' => '</div>',
163
    );
164

    
165
    $form['left'] = array(
166
      '#prefix' => '<div class="ctools-left-container clearfix">',
167
      '#suffix' => '</div>',
168
    );
169

    
170
    // Set this up and we can use CTools' Export UI's built in wizard caching,
171
    // which already has callbacks for the context cache under this name.
172
    $module = 'export_ui::' . $this->plugin['name'];
173
    $name = $this->edit_cache_get_key($form_state['item'], $form_state['form type']);
174

    
175
    ctools_context_add_context_form($module, $form, $form_state, $form['right']['contexts_table'], $form_state['item'], $name);
176
    ctools_context_add_required_context_form($module, $form, $form_state, $form['left']['required_contexts_table'], $form_state['item'], $name);
177
    ctools_context_add_relationship_form($module, $form, $form_state, $form['right']['relationships_table'], $form_state['item'], $name);
178
  }
179

    
180
  function edit_form_context_submit(&$form, &$form_state) {
181
    // Prevent this from going to edit_form_submit();
182
  }
183

    
184
  function edit_form_layout(&$form, &$form_state) {
185
    ctools_include('common', 'panels');
186
    ctools_include('display-layout', 'panels');
187
    ctools_include('plugins', 'panels');
188

    
189
    // @todo -- figure out where/how to deal with this.
190
    $form_state['allowed_layouts'] = 'panels_mini';
191

    
192
    if ($form_state['op'] == 'add' && empty($form_state['item']->display)) {
193
      $form_state['item']->display = panels_new_display();
194
    }
195

    
196
    $form_state['display'] = &$form_state['item']->display;
197

    
198
    // Tell the Panels form not to display buttons.
199
    $form_state['no buttons'] = TRUE;
200

    
201
    // Change the #id of the form so the CSS applies properly.
202
    $form['#id'] = 'panels-choose-layout';
203
    $form = panels_choose_layout($form, $form_state);
204

    
205
    if ($form_state['op'] == 'edit') {
206
      $form['buttons']['next']['#value'] = t('Change');
207
    }
208
  }
209

    
210
  /**
211
   * Validate that a layout was chosen.
212
   */
213
  function edit_form_layout_validate(&$form, &$form_state) {
214
    $display = &$form_state['display'];
215
    if (empty($form_state['values']['layout'])) {
216
      form_error($form['layout'], t('You must select a layout.'));
217
    }
218
    if ($form_state['op'] == 'edit') {
219
      if ($form_state['values']['layout'] == $display->layout) {
220
        form_error($form['layout'], t('You must select a different layout if you wish to change layouts.'));
221
      }
222
    }
223
  }
224

    
225
  /**
226
   * A layout has been selected, set it up.
227
   */
228
  function edit_form_layout_submit(&$form, &$form_state) {
229
    $display = &$form_state['display'];
230
    if ($form_state['op'] == 'edit') {
231
      if ($form_state['values']['layout'] != $display->layout) {
232
        $form_state['item']->temp_layout = $form_state['values']['layout'];
233
        $form_state['clicked_button']['#next'] = 'move';
234
      }
235
    }
236
    else {
237
      $form_state['item']->display->layout = $form_state['values']['layout'];
238
    }
239
  }
240

    
241
  /**
242
   * When a layout is changed, the user is given the opportunity to move content.
243
   */
244
  function edit_form_move(&$form, &$form_state) {
245
    $form_state['display'] = &$form_state['item']->display;
246
    $form_state['layout'] = $form_state['item']->temp_layout;
247

    
248
    ctools_include('common', 'panels');
249
    ctools_include('display-layout', 'panels');
250
    ctools_include('plugins', 'panels');
251

    
252
    // Tell the Panels form not to display buttons.
253
    $form_state['no buttons'] = TRUE;
254

    
255
    // Change the #id of the form so the CSS applies properly.
256
    $form = panels_change_layout($form, $form_state);
257

    
258
    // This form is outside the normal wizard list, so we need to specify the
259
    // previous/next forms.
260
    $form['buttons']['previous']['#next'] = 'layout';
261
    $form['buttons']['next']['#next'] = 'content';
262
  }
263

    
264
  function edit_form_move_submit(&$form, &$form_state) {
265
    panels_change_layout_submit($form, $form_state);
266
  }
267

    
268
  function edit_form_content(&$form, &$form_state) {
269
    ctools_include('ajax');
270
    ctools_include('plugins', 'panels');
271
    ctools_include('display-edit', 'panels');
272
    ctools_include('context');
273

    
274
    // If we are cloning an item, we MUST have this cached for this to work,
275
    // so make sure:
276
    if ($form_state['form type'] == 'clone' && empty($form_state['item']->export_ui_item_is_cached)) {
277
      $this->edit_cache_set($form_state['item'], 'clone');
278
    }
279

    
280
    $cache = panels_edit_cache_get('panels_mini:' . $this->edit_cache_get_key($form_state['item'], $form_state['form type']));
281

    
282
    $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display);
283
    $form_state['renderer']->cache = &$cache;
284

    
285
    $form_state['display'] = &$cache->display;
286
    $form_state['content_types'] = $cache->content_types;
287
    // Tell the Panels form not to display buttons.
288
    $form_state['no buttons'] = TRUE;
289
    $form_state['display_title'] = !empty($cache->display_title);
290

    
291
    $form = panels_edit_display_form($form, $form_state);
292
  }
293

    
294
  function edit_form_content_submit(&$form, &$form_state) {
295
    panels_edit_display_form_submit($form, $form_state);
296
    $form_state['item']->display = $form_state['display'];
297
  }
298
}