Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / stylizer / plugins / export_ui / stylizer_ui.class.php @ 13755f8d

1
<?php
2

    
3
/**
4
 * UI class for Stylizer.
5
 */
6
class stylizer_ui extends ctools_export_ui {
7

    
8
  function access($op, $item) {
9
    $access = parent::access($op, $item);
10
    if ($op == 'add' && $access && empty($this->base_types)) {
11
     // Make sure there are base styles defined.
12
     $access = FALSE;
13
    }
14
    return $access;
15
  }
16

    
17
  function list_form(&$form, &$form_state) {
18
    ctools_include('stylizer');
19
    parent::list_form($form, $form_state);
20

    
21
    $all = array('all' => t('- All -'));
22

    
23
    if (empty($this->base_types)) {
24
      // Give a warning about the missing base styles.
25
      drupal_set_message($this->plugin['strings']['message']['missing base type'], 'warning');
26
    }
27

    
28
    $types = $all;
29
    foreach ($this->base_types as $module => $info) {
30
      foreach ($info as $key => $base_type) {
31
        $types[$module . '-' . $key] = $base_type['title'];
32
      }
33
    }
34

    
35
    $form['top row']['type'] = array(
36
      '#type' => 'select',
37
      '#title' => t('Type'),
38
      '#options' => $types,
39
      '#default_value' => 'all',
40
      '#weight' => -10,
41
      '#attributes' => array('class' => array('ctools-auto-submit')),
42
    );
43

    
44
    $plugins = ctools_get_style_bases();
45
    $form_state['style_plugins'] = $plugins;
46

    
47
    $options = $all;
48
    // @todo base should use $module . '-' . $name
49
    foreach ($plugins as $name => $plugin) {
50
      $options[$name] = $plugin['title'];
51
    }
52

    
53
    $form['top row']['base'] = array(
54
      '#type' => 'select',
55
      '#title' => t('Base'),
56
      '#options' => $all + $options,
57
      '#default_value' => 'all',
58
      '#weight' => -9,
59
      '#attributes' => array('class' => array('ctools-auto-submit')),
60
    );
61
  }
62

    
63
  function list_sort_options() {
64
    return array(
65
      'disabled' => t('Enabled, title'),
66
      'title' => t('Title'),
67
      'name' => t('Name'),
68
      'base' => t('Base'),
69
      'type' => t('Type'),
70
      'storage' => t('Storage'),
71
    );
72
  }
73

    
74
  function list_filter($form_state, $item) {
75
    if (empty($form_state['style_plugins'][$item->settings['style_base']])) {
76
      $this->style_plugin = array(
77
        'name' => 'broken',
78
        'title' => t('Missing plugin'),
79
        'type' => t('Unknown'),
80
        'module' => '',
81
      );
82
    }
83
    else {
84
      $this->style_plugin = $form_state['style_plugins'][$item->settings['style_base']];
85
    }
86

    
87
    // This isn't really a field, but by setting this we can list it in the
88
    // filter fields and have the search box pick it up.
89
    $item->plugin_title = $this->style_plugin['title'];
90

    
91
    if ($form_state['values']['type'] != 'all') {
92
      list($module, $type) = explode('-', $form_state['values']['type']);
93
      if ($module != $this->style_plugin['module'] || $type != $this->style_plugin['type']) {
94
        return TRUE;
95
      }
96
    }
97

    
98
    if ($form_state['values']['base'] != 'all' && $form_state['values']['base'] != $this->style_plugin['name']) {
99
      return TRUE;
100
    }
101

    
102
    return parent::list_filter($form_state, $item);
103
  }
104

    
105
  function list_search_fields() {
106
    $fields = parent::list_search_fields();
107
    $fields[] = 'plugin_title';
108
    return $fields;
109
  }
110

    
111
  function list_build_row($item, &$form_state, $operations) {
112
    // Set up sorting
113
    switch ($form_state['values']['order']) {
114
      case 'disabled':
115
        $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
116
        break;
117
      case 'title':
118
        $this->sorts[$item->name] = $item->admin_title;
119
        break;
120
      case 'name':
121
        $this->sorts[$item->name] = $item->name;
122
        break;
123
      case 'type':
124
        $this->sorts[$item->name] = $this->style_plugin['type'] . $item->admin_title;
125
        break;
126
      case 'base':
127
        $this->sorts[$item->name] = $this->style_plugin['title'] . $item->admin_title;
128
        break;
129
      case 'storage':
130
        $this->sorts[$item->name] = $item->type . $item->admin_title;
131
        break;
132
    }
133

    
134
    if (!empty($this->base_types[$this->style_plugin['module']][$this->style_plugin['type']])) {
135
      $type = $this->base_types[$this->style_plugin['module']][$this->style_plugin['type']]['title'];
136
    }
137
    else {
138
      $type = t('Unknown');
139
    }
140

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

    
143
    $this->rows[$item->name] = array(
144
      'data' => array(
145
        array('data' => $type, 'class' => array('ctools-export-ui-type')),
146
        array('data' => check_plain($item->name), 'class' => array('ctools-export-ui-name')),
147
        array('data' => check_plain($item->admin_title), 'class' => array('ctools-export-ui-title')),
148
        array('data' => check_plain($this->style_plugin['title']), 'class' => array('ctools-export-ui-base')),
149
        array('data' => check_plain($item->type), 'class' => array('ctools-export-ui-storage')),
150
        array('data' => $ops, 'class' => array('ctools-export-ui-operations')),
151
      ),
152
      'title' => check_plain($item->admin_description),
153
      'class' => array(!empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled'),
154
    );
155
  }
156

    
157
  function list_table_header() {
158
    return array(
159
      array('data' => t('Type'), 'class' => array('ctools-export-ui-type')),
160
      array('data' => t('Name'), 'class' => array('ctools-export-ui-name')),
161
      array('data' => t('Title'), 'class' => array('ctools-export-ui-title')),
162
      array('data' => t('Base'), 'class' => array('ctools-export-ui-base')),
163
      array('data' => t('Storage'), 'class' => array('ctools-export-ui-storage')),
164
      array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations')),
165
    );
166
  }
167

    
168
  function init($plugin) {
169
    ctools_include('stylizer');
170
    $this->base_types = ctools_get_style_base_types();
171

    
172
    parent::init($plugin);
173
  }
174

    
175
  function get_wizard_info(&$form_state) {
176
    $form_info = parent::get_wizard_info($form_state);
177
    ctools_include('stylizer');
178

    
179
    // For add forms, we have temporarily set the 'form type' to include
180
    // the style type so the default wizard_info can find the path. If
181
    // we did that, we have to put it back.
182
    if (!empty($form_state['type'])) {
183
      $form_state['form type'] = 'add';
184
      $form_info['show back'] = TRUE;
185
    }
186

    
187
    // Ensure these do not get out of sync.
188
    $form_state['item']->settings['name'] = $form_state['item']->name;
189
    $form_state['settings'] = $form_state['item']->settings;
190

    
191
    // Figure out the base style plugin in use and make sure that is available.
192
    $plugin = NULL;
193
    if (!empty($form_state['item']->settings['style_base'])) {
194
      $plugin = ctools_get_style_base($form_state['item']->settings['style_base']);
195
      ctools_stylizer_add_plugin_forms($form_info, $plugin, $form_state['op']);
196
    }
197
    else {
198
      // This is here so the 'finish' button does not show up, and because
199
      // we don't have the selected style we don't know what the next form(s)
200
      // will be.
201
      $form_info['order']['next'] = t('Configure style');
202

    
203
    }
204

    
205
    // If available, make sure these are available for the 'choose' form.
206
    if (!empty($form_state['item']->style_module)) {
207
      $form_state['module'] = $form_state['item']->style_module;
208
      $form_state['type'] = $form_state['item']->style_type;
209
    }
210

    
211
    $form_state['base_style_plugin'] = $plugin;
212
    $form_state['settings'] = $form_state['item']->settings;
213
    return $form_info;
214
  }
215

    
216
  /**
217
   * Store the stylizer info in our settings.
218
   *
219
   * The stylizer wizard stores its stuff in slightly different places, so
220
   * we have to find it and move it to the right place.
221
   */
222
  function store_stylizer_info(&$form_state) {
223
    /*
224
    foreach (array('name', 'admin_title', 'admin_description') as $key) {
225
      if (!empty($form_state['values'][$key])) {
226
        $form_state['item']->{$key} = $form_state['values'][$key];
227
      }
228
    }
229
    */
230

    
231
    if ($form_state['step'] != 'import') {
232
      $form_state['item']->settings = $form_state['settings'];
233
    }
234
    // Do not let the 'name' accidentally get out of sync under any circumstances.
235
    $form_state['item']->settings['name'] = $form_state['item']->name;
236
  }
237

    
238
  function edit_wizard_next(&$form_state) {
239
    $this->store_stylizer_info($form_state);
240
    parent::edit_wizard_next($form_state);
241
  }
242

    
243
  function edit_wizard_finish(&$form_state) {
244
    // These might be stored by the stylizer wizard, so we should clear them.
245
    if (isset($form_state['settings']['old_settings'])) {
246
      unset($form_state['settings']['old_settings']);
247
    }
248
    $this->store_stylizer_info($form_state);
249
    parent::edit_wizard_finish($form_state);
250
  }
251

    
252
  function edit_form_type(&$form, &$form_state) {
253
    foreach ($this->base_types as $module => $info) {
254
      foreach ($info as $key => $base_type) {
255
        $types[$module . '-' . $key] = $base_type['title'];
256
      }
257
    }
258

    
259
    $form['type'] = array(
260
      '#type' => 'select',
261
      '#title' => t('Type'),
262
      '#options' => $types,
263
      '#default_value' => 'all',
264
      '#weight' => -10,
265
      '#attributes' => array('class' => array('ctools-auto-submit')),
266
    );
267
  }
268

    
269
  function edit_form_type_submit(&$form, &$form_state) {
270
    list($form_state['item']->style_module, $form_state['item']->style_type) = explode('-', $form_state['values']['type']);
271
  }
272
}