Projet

Général

Profil

Paste
Télécharger (11,2 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_slideshow / views_slideshow_plugin_style_slideshow.inc @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains the list style plugin.
6
 */
7

    
8
/**
9
 * Style plugin to render each item in a slideshow of an ordered or unordered list.
10
 *
11
 * @ingroup views_style_plugins
12
 */
13
class views_slideshow_plugin_style_slideshow extends views_plugin_style {
14

    
15
  // Set default options
16
  function option_definition() {
17
    $options = parent::option_definition();
18

    
19
    // Load all include files from views slideshow addons.
20
    module_load_all_includes('views_slideshow.inc');
21

    
22
    // call every module using hook_views_slideshow_option_definition and merge
23
    // it's return value with the other default options.
24
    return array_merge($options, module_invoke_all('views_slideshow_option_definition'));
25
  }
26

    
27
  // Build the settings form for the view.
28
  function options_form(&$form, &$form_state) {
29
    // Include ctools dependent support
30
    ctools_include('dependent');
31

    
32
    // load up all views slideshow modules functions.
33
    module_load_all_includes('views_slideshow.inc');
34
    parent::options_form($form, $form_state);
35

    
36
    // Wrap all the form elements to help style the form.
37
    $form['views_slideshow_wrapper'] = array(
38
      '#markup' => '<div id="views-slideshow-form-wrapper">',
39
    );
40

    
41
    // Style
42
    $form['slideshow_skin_header'] = array(
43
      '#markup' => '<h2>' . t('Style') . '</h2>',
44
    );
45

    
46
    // Get a list of all available skins.
47
    $skin_info = $this->views_slideshow_get_skins();
48
    foreach ($skin_info as $skin => $info) {
49
      $skins[$skin] = $info['name'];
50
    }
51
    asort($skins);
52

    
53
    // Create the drop down box so users can choose an available skin.
54
    $form['slideshow_skin'] = array(
55
      '#type' => 'select',
56
      '#title' => t('Skin'),
57
      '#options' => $skins,
58
      '#default_value' => $this->options['slideshow_skin'],
59
      '#description' => t('Select the skin to use for this display.  Skins allow for easily swappable layouts of things like next/prev links and thumbnails.  Note that not all skins support all widgets, so a combination of skins and widgets may lead to unpredictable results in layout.'),
60
    );
61

    
62
    /**
63
     * Slides
64
     */
65
    $form['slides_header'] = array(
66
      '#markup' => '<h2>' . t('Slides') . '</h2>',
67
    );
68

    
69
    // Get all slideshow types.
70
    $slideshows = module_invoke_all('views_slideshow_slideshow_info');
71

    
72
    if ($slideshows) {
73

    
74
      // Build our slideshow options for the form.
75
      $slideshow_options = array();
76
      foreach ($slideshows as $slideshow_id => $slideshow_info) {
77
        $slideshow_options[$slideshow_id] = $slideshow_info['name'];
78
      }
79

    
80
      $form['slideshow_type'] = array(
81
        '#type' => 'select',
82
        '#title' => t('Slideshow Type'),
83
        '#options' => $slideshow_options,
84
        '#default_value' => $this->options['slideshow_type'],
85
      );
86

    
87
      $arguments = array(
88
        &$form,
89
        &$form_state,
90
        &$this,
91
      );
92

    
93
      foreach (module_implements('views_slideshow_slideshow_type_form') as $module) {
94
        $form[$module] = array(
95
          '#type' => 'fieldset',
96
          '#title' => t('!module options', array('!module' => $slideshows[$module]['name'])),
97
          '#collapsible' => TRUE,
98
          '#attributes' => array('class' => array($module)),
99
          '#states' => array(
100
            'visible' => array(
101
              ':input[name="style_options[slideshow_type]"]' => array('value' => $module),
102
            ),
103
          ),
104
        );
105

    
106
        $function = $module . '_views_slideshow_slideshow_type_form';
107
        call_user_func_array($function, $arguments);
108
      }
109
    }
110
    else {
111
      $form['enable_module'] = array(
112
        '#markup' => t('There is no Views Slideshow plugin enabled. Go to the !modules and enable a Views Slideshow plugin module. For example Views Slideshow Singleframe.', array('!modules' => l('Modules Page', 'admin/modules'))),
113
      );
114
    }
115

    
116
    /**
117
     * Widgets
118
     */
119
    $form['widgets_header'] = array(
120
      '#markup' => '<h2>' . t('Widgets') . '</h2>',
121
    );
122

    
123
    // Loop through all locations so we can add header for each location.
124
    $location = array('top' => t('Top'), 'bottom' => t('Bottom'));
125
    foreach ($location as $location_id => $location_name) {
126
      // Widget Header
127
      $form['widgets'][$location_id]['header'] = array(
128
        '#markup' => '<h3>' . t('!location Widgets', array('!location' => $location_name)) . '</h3>',
129
      );
130
    }
131

    
132
    // Get all widgets that are registered.
133
    // If we have widgets then build it's form fields.
134
    $widgets = module_invoke_all('views_slideshow_widget_info');
135
    if (!empty($widgets)) {
136

    
137
      // Build our weight values by number of widgets
138
      $weights = array();
139
      for ($i = 1; $i <= count($widgets); $i++) {
140
        $weights[$i] = $i;
141
      }
142

    
143
      // Loop through our widgets and locations to build our form values for
144
      // each widget.
145
      foreach ($widgets as $widget_id => $widget_info) {
146
        foreach ($location as $location_id => $location_name) {
147
          $widget_dependency = 'style_options[widgets][' . $location_id . '][' . $widget_id . ']';
148

    
149
          // Determine if a widget is compatible with a slideshow.
150
          $compatible_slideshows = array();
151
          foreach ($slideshows as $slideshow_id => $slideshow_info) {
152
            $is_compatible = 1;
153
            // Check if every required accept value in the widget has a
154
            // corresponding calls value in the slideshow.
155
            foreach($widget_info['accepts'] as $accept_key => $accept_value) {
156
              if (is_array($accept_value) && !empty($accept_value['required']) && !in_array($accept_key, $slideshow_info['calls'])) {
157
                $is_compatible = 0;
158
                break;
159
              }
160
            }
161

    
162
            // No need to go through this if it's not compatible.
163
            if ($is_compatible) {
164
              // Check if every required calls value in the widget has a
165
              // corresponding accepts call.
166
              foreach($widget_info['calls'] as $calls_key => $calls_value) {
167
                if (is_array($calls_value) && !empty($calls_value['required']) && !in_array($calls_key, $slideshow_info['accepts'])) {
168
                  $is_compatible = 0;
169
                  break;
170
                }
171
              }
172
            }
173

    
174
            // If it passed all those tests then they are compatible.
175
            if ($is_compatible) {
176
              $compatible_slideshows[] = $slideshow_id;
177
            }
178
          }
179

    
180
          // Use Widget Checkbox
181
          $form['widgets'][$location_id][$widget_id]['enable'] = array(
182
            '#type' => 'checkbox',
183
            '#title' => t($widget_info['name']),
184
            '#default_value' => $this->options['widgets'][$location_id][$widget_id]['enable'],
185
            '#description' => t('Should !name be rendered at the !location of the slides.', array('!name' => $widget_info['name'], '!location' => $location_name)),
186
          );
187

    
188
          $form['widgets'][$location_id][$widget_id]['enable']['#dependency']['edit-style-options-slideshow-type'] = !empty($compatible_slideshows) ? $compatible_slideshows : array('none');
189

    
190
          // Need to wrap this so it indents correctly.
191
          $form['widgets'][$location_id][$widget_id]['wrapper'] = array(
192
            '#markup' => '<div class="vs-dependent">',
193
          );
194

    
195
          // Widget weight
196
          // We check to see if the default value is greater than the number of
197
          // widgets just in case a widget has been removed and the form hasn't
198
          // hasn't been saved again.
199
          $form['widgets'][$location_id][$widget_id]['weight'] = array(
200
            '#type' => 'select',
201
            '#title' => t('Weight of the !name', array('!name' => $widget_info['name'])),
202
            '#default_value' => ($this->options['widgets'][$location_id][$widget_id]['weight'] > count($widgets)) ? count($widgets) : $this->options['widgets'][$location_id][$widget_id]['weight'],
203
            '#options' => $weights,
204
            '#description' => t('Determines in what order the !name appears.  A lower weight will cause the !name to be above higher weight items.', array('!name' => $widget_info['name'])),
205
            '#prefix' => '<div class="vs-dependent">',
206
            '#suffix' => '</div>',
207
            '#states' => array(
208
              'visible' => array(
209
                ':input[name="style_options[widgets][' . $location_id . '][' . $widget_id . '][enable]"]' => array('checked' => TRUE),
210
              ),
211
            ),
212
          );
213

    
214
          // Add all the widget settings.
215
          if (function_exists($widget_id . '_views_slideshow_widget_form_options')) {
216
            $arguments = array(
217
              &$form['widgets'][$location_id][$widget_id],
218
              &$form_state,
219
              &$this,
220
              $this->options['widgets'][$location_id][$widget_id],
221
              $widget_dependency,
222
            );
223
            call_user_func_array($widget_id . '_views_slideshow_widget_form_options', $arguments);
224
          }
225

    
226
          $form['widgets'][$location_id][$widget_id]['wrapper_close'] = array(
227
            '#markup' => '</div>',
228
          );
229
        }
230
      }
231
    }
232

    
233
    $form['views_slideshow_wrapper_close'] = array(
234
      '#markup' => '</div>',
235
    );
236
  }
237

    
238
  // Run any validation on the form settings.
239
  function options_validate(&$form, &$form_state) {
240
    module_load_all_includes('views_slideshow.inc');
241

    
242
    $arguments = array(
243
      &$form,
244
      &$form_state,
245
      &$this,
246
    );
247

    
248
    // Call all modules that use hook_views_slideshow_options_form_validate
249
    foreach (module_implements('views_slideshow_options_form_validate') as $module) {
250
      $function = $module . '_views_slideshow_options_form_validate';
251
      call_user_func_array($function, $arguments);
252
    }
253
  }
254

    
255
  // Run any necessary actions on submit.
256
  function options_submit(&$form, &$form_state) {
257
    module_load_all_includes('views_slideshow.inc');
258

    
259
    $arguments = array(
260
      $form,
261
      &$form_state,
262
    );
263

    
264
    // Call all modules that use hook_views_slideshow_options_form_submit
265
    foreach (module_implements('views_slideshow_options_form_submit') as $module) {
266
      $function = $module . '_views_slideshow_options_form_submit';
267
      call_user_func_array($function, $arguments);
268
    }
269

    
270
    // In addition to the skin, we also pre-save the definition that
271
    // correspond to it.  That lets us avoid a hook lookup on every page.
272
    $skins = $this->views_slideshow_get_skins();
273
    $form_state['values']['style_options']['skin_info'] = $skins[$form_state['values']['style_options']['slideshow_skin']];
274
  }
275

    
276
  /**
277
   * Retrieve a list of all available skins in the system.
278
   */
279
  function views_slideshow_get_skins() {
280
    static $skins;
281

    
282
    if (empty($skins)) {
283
      $skins = array();
284

    
285
      // Call all modules that use hook_views_slideshow_skin_info
286
      foreach (module_implements('views_slideshow_skin_info') as $module) {
287
        $skin_items = call_user_func($module . '_views_slideshow_skin_info');
288
        if (isset($skin_items) && is_array($skin_items)) {
289
          foreach (array_keys($skin_items) as $skin) {
290
            // Ensure that the definition is complete, so we don't need lots
291
            // of error checking later.
292
            $skin_items[$skin] += array(
293
              'class' => 'default',
294
              'name' => t('Untitled skin'),
295
              'module' => $module,
296
              'path' => '',
297
              'stylesheets' => array(),
298
            );
299
          }
300
          $skins = array_merge($skins, $skin_items);
301
        }
302
      }
303
    }
304

    
305
    return $skins;
306
  }
307
}