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 @ 64156087

1
<?php
2

    
3
/**
4
 * @file
5
 */
6
class panels_mini_ui extends ctools_export_ui {
7
  function init($plugin) {
8
    parent::init($plugin);
9
    ctools_include('context');
10
  }
11

    
12
  function list_form(&$form, &$form_state) {
13
    ctools_include('plugins', 'panels');
14
    $this->layouts = panels_get_layouts();
15

    
16
    parent::list_form($form, $form_state);
17

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

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

    
31
    foreach ($this->layouts as $name => $plugin) {
32
      $layouts[$name] = $plugin['title'];
33
    }
34

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

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

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

    
53
    return parent::list_filter($form_state, $item);
54
  }
55

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

    
67
  function list_build_row($item, &$form_state, $operations) {
68
    // Set up sorting.
69
    switch ($form_state['values']['order']) {
70
      case 'disabled':
71
        $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
72
        break;
73

    
74
      case 'title':
75
        $this->sorts[$item->name] = $item->admin_title;
76
        break;
77

    
78
      case 'name':
79
        $this->sorts[$item->name] = $item->name;
80
        break;
81

    
82
      case 'category':
83
        $this->sorts[$item->name] = ($item->category ? $item->category : t('Mini panels')) . $item->admin_title;
84
        break;
85

    
86
      case 'layout':
87
        $this->sorts[$item->name] = $item->display->layout . $item->admin_title;
88
        break;
89

    
90
      case 'storage':
91
        $this->sorts[$item->name] = $item->type . $item->admin_title;
92
        break;
93
    }
94

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

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

    
100
    $this->rows[$item->name] = array(
101
      'data' => array(
102
        array('data' => check_plain($item->admin_title), 'class' => array('ctools-export-ui-title')),
103
        array('data' => check_plain($item->name), 'class' => array('ctools-export-ui-name')),
104
        array('data' => $category, 'class' => array('ctools-export-ui-category')),
105
        array('data' => $layout, 'class' => array('ctools-export-ui-layout')),
106
        array('data' => $item->type, 'class' => array('ctools-export-ui-storage')),
107
        array('data' => $ops, 'class' => array('ctools-export-ui-operations')),
108
      ),
109
      'title' => !empty($item->admin_description) ? check_plain($item->admin_description) : '',
110
      'class' => array(!empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled'),
111
    );
112
  }
113

    
114
  function list_table_header() {
115
    return array(
116
      array('data' => t('Title'), 'class' => array('ctools-export-ui-title')),
117
      array('data' => t('Name'), 'class' => array('ctools-export-ui-name')),
118
      array('data' => t('Category'), 'class' => array('ctools-export-ui-category')),
119
      array('data' => t('Layout'), 'class' => array('ctools-export-ui-layout')),
120
      array('data' => t('Storage'), 'class' => array('ctools-export-ui-storage')),
121
      array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations')),
122
    );
123
  }
124

    
125
  function edit_form(&$form, &$form_state) {
126
    // Get the basic edit form.
127
    parent::edit_form($form, $form_state);
128

    
129
    // Set the admin title machine name length.
130
    // We need to do this because the system block name length is
131
    // limited to 32 chars.
132
    $form['info']['name']['#maxlength'] = 32;
133
    $form['info']['name']['#size'] = 34;
134
    $form['info']['name']['#description'] .= ' ' . t('The machine name length is limited to 32 characters, due to a limitation in the core block system.');
135

    
136
    $form['category'] = array(
137
      '#type' => 'textfield',
138
      '#size' => 24,
139
      '#default_value' => $form_state['item']->category,
140
      '#title' => t('Category'),
141
      '#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'."),
142
    );
143

    
144
    $form['title']['#title'] = t('Title');
145
    $form['title']['#description'] = t('The title for this mini panel. It can be overridden in the block configuration.');
146
  }
147

    
148
  /**
149
   * Validate submission of the mini panel edit form.
150
   */
151
  function edit_form_basic_validate($form, &$form_state) {
152
    parent::edit_form_validate($form, $form_state);
153
    if (preg_match("/[^A-Za-z0-9 ]/", $form_state['values']['category'])) {
154
      form_error($form['category'], t('Categories may contain only alphanumerics or spaces.'));
155
    }
156
  }
157

    
158
  function edit_form_submit(&$form, &$form_state) {
159
    parent::edit_form_submit($form, $form_state);
160
    $form_state['item']->category = $form_state['values']['category'];
161
  }
162

    
163
  function edit_form_context(&$form, &$form_state) {
164
    ctools_include('context-admin');
165
    ctools_context_admin_includes();
166
    ctools_add_css('ruleset');
167

    
168
    $form['right'] = array(
169
      '#prefix' => '<div class="ctools-right-container">',
170
      '#suffix' => '</div>',
171
    );
172

    
173
    $form['left'] = array(
174
      '#prefix' => '<div class="ctools-left-container clearfix">',
175
      '#suffix' => '</div>',
176
    );
177

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

    
183
    ctools_context_add_context_form($module, $form, $form_state, $form['right']['contexts_table'], $form_state['item'], $name);
184
    ctools_context_add_required_context_form($module, $form, $form_state, $form['left']['required_contexts_table'], $form_state['item'], $name);
185
    ctools_context_add_relationship_form($module, $form, $form_state, $form['right']['relationships_table'], $form_state['item'], $name);
186
  }
187

    
188
  function edit_form_context_submit(&$form, &$form_state) {
189
    // Prevent this from going to edit_form_submit();
190
  }
191

    
192
  function edit_form_layout(&$form, &$form_state) {
193
    ctools_include('common', 'panels');
194
    ctools_include('display-layout', 'panels');
195
    ctools_include('plugins', 'panels');
196

    
197
    // @todo -- figure out where/how to deal with this.
198
    $form_state['allowed_layouts'] = 'panels_mini';
199

    
200
    if ($form_state['op'] == 'add' && empty($form_state['item']->display)) {
201
      $form_state['item']->display = panels_new_display();
202
    }
203

    
204
    $form_state['display'] = &$form_state['item']->display;
205

    
206
    // Tell the Panels form not to display buttons.
207
    $form_state['no buttons'] = TRUE;
208

    
209
    // Change the #id of the form so the CSS applies properly.
210
    $form['#id'] = 'panels-choose-layout';
211
    $form = panels_choose_layout($form, $form_state);
212

    
213
    if ($form_state['op'] == 'edit') {
214
      $form['buttons']['next']['#value'] = t('Change');
215
    }
216
  }
217

    
218
  /**
219
   * Validate that a layout was chosen.
220
   */
221
  function edit_form_layout_validate(&$form, &$form_state) {
222
    $display = &$form_state['display'];
223
    if (empty($form_state['values']['layout'])) {
224
      form_error($form['layout'], t('You must select a layout.'));
225
    }
226
    if ($form_state['op'] == 'edit') {
227
      if ($form_state['values']['layout'] == $display->layout) {
228
        form_error($form['layout'], t('You must select a different layout if you wish to change layouts.'));
229
      }
230
    }
231
  }
232

    
233
  /**
234
   * A layout has been selected, set it up.
235
   */
236
  function edit_form_layout_submit(&$form, &$form_state) {
237
    $display = &$form_state['display'];
238
    if ($form_state['op'] == 'edit') {
239
      if ($form_state['values']['layout'] != $display->layout) {
240
        $form_state['item']->temp_layout = $form_state['values']['layout'];
241
        $form_state['clicked_button']['#next'] = 'move';
242
      }
243
    }
244
    else {
245
      $form_state['item']->display->layout = $form_state['values']['layout'];
246
    }
247
  }
248

    
249
  /**
250
   * When a layout is changed, the user is given the opportunity to move content.
251
   */
252
  function edit_form_move(&$form, &$form_state) {
253
    $form_state['display'] = &$form_state['item']->display;
254
    $form_state['layout'] = $form_state['item']->temp_layout;
255

    
256
    ctools_include('common', 'panels');
257
    ctools_include('display-layout', 'panels');
258
    ctools_include('plugins', 'panels');
259

    
260
    // Tell the Panels form not to display buttons.
261
    $form_state['no buttons'] = TRUE;
262

    
263
    // Change the #id of the form so the CSS applies properly.
264
    $form = panels_change_layout($form, $form_state);
265

    
266
    // This form is outside the normal wizard list, so we need to specify the
267
    // previous/next forms.
268
    $form['buttons']['previous']['#next'] = 'layout';
269
    $form['buttons']['next']['#next'] = 'content';
270
  }
271

    
272
  function edit_form_move_submit(&$form, &$form_state) {
273
    panels_change_layout_submit($form, $form_state);
274
  }
275

    
276
  function edit_form_content(&$form, &$form_state) {
277
    ctools_include('ajax');
278
    ctools_include('plugins', 'panels');
279
    ctools_include('display-edit', 'panels');
280
    ctools_include('context');
281

    
282
    // If we are cloning an item, we MUST have this cached for this to work,
283
    // so make sure:
284
    if ($form_state['form type'] == 'clone' && empty($form_state['item']->export_ui_item_is_cached)) {
285
      $this->edit_cache_set($form_state['item'], 'clone');
286
    }
287

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

    
290
    $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display);
291
    $form_state['renderer']->cache = &$cache;
292

    
293
    $form_state['display'] = &$cache->display;
294
    $form_state['content_types'] = $cache->content_types;
295
    // Tell the Panels form not to display buttons.
296
    $form_state['no buttons'] = TRUE;
297
    $form_state['display_title'] = !empty($cache->display_title);
298

    
299
    $form = panels_edit_display_form($form, $form_state);
300
  }
301

    
302
  function edit_form_content_submit(&$form, &$form_state) {
303
    panels_edit_display_form_submit($form, $form_state);
304
    $form_state['item']->display = $form_state['display'];
305
  }
306

    
307
}