Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / views_content / plugins / views / views_content_plugin_display_ctools_context.inc @ 6e3ce7c2

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains the block display plugin.
6
 */
7

    
8
/**
9
 * The plugin that handles a block.
10
 *
11
 * @ingroup views_display_plugins
12
 */
13
class views_content_plugin_display_ctools_context extends views_plugin_display {
14
  /**
15
   * If this variable is true, this display counts as a context. We use this
16
   * variable so that we can easily build plugins against this display type.
17
   */
18
  public $context_display = TRUE;
19

    
20

    
21
  public function get_style_type() {
22
    return 'context';
23
  }
24

    
25

    
26
  public function defaultable_sections($section = NULL) {
27
    if (in_array($section, array('style_options', 'style_plugin', 'row_options', 'row_plugin'))) {
28
      return FALSE;
29
    }
30

    
31
    return parent::defaultable_sections($section);
32
  }
33

    
34

    
35
  public function option_definition() {
36
    $options = parent::option_definition();
37

    
38
    $options['admin_title'] = array('default' => '', 'translatable' => TRUE);
39

    
40
    // Overrides for standard stuff:
41
    $options['style_plugin']['default'] = 'ctools_context';
42
    $options['row_plugin']['default'] = 'fields';
43
    $options['defaults']['default']['style_plugin'] = FALSE;
44
    $options['defaults']['default']['style_options'] = FALSE;
45
    $options['defaults']['default']['row_plugin'] = FALSE;
46
    $options['defaults']['default']['row_options'] = FALSE;
47
    $options['inherit_panels_path'] = array('default' => 0);
48
    $options['argument_input'] = array('default' => array());
49

    
50
    return $options;
51
  }
52

    
53
  /**
54
   * The display block handler returns the structure necessary for a block.
55
   */
56
  public function execute() {
57
    $this->executing = TRUE;
58
    return $this->view->render();
59
  }
60

    
61

    
62
  public function preview() {
63
    $this->previewing = TRUE;
64
    return $this->view->render();
65
  }
66

    
67
  /**
68
   * Render this display.
69
   */
70
  public function render() {
71
    if (!empty($this->previewing)) {
72
      return theme($this->theme_functions(), array('view' => $this->view));
73
    }
74
    else {
75
      // We want to process the view like we're theming it, but not actually
76
      // use the template part. Therefore we run through all the preprocess
77
      // functions which will populate the variables array.
78
      $hooks = theme_get_registry();
79
      $info = $hooks[$this->definition['theme']];
80
      if (!empty($info['file'])) {
81
        @include_once './' . $info['path'] . '/' . $info['file'];
82
      }
83
      $this->variables = array('view' => &$this->view);
84

    
85
      if (isset($info['preprocess functions']) && is_array($info['preprocess functions'])) {
86
        foreach ($info['preprocess functions'] as $preprocess_function) {
87
          if (function_exists($preprocess_function)) {
88
            $preprocess_function($this->variables, $this->definition['theme']);
89
          }
90
        }
91
      }
92
    }
93

    
94
    return $this->variables;
95
  }
96

    
97
  /**
98
   * Provide the summary for page options in the views UI.
99
   *
100
   * This output is returned as an array.
101
   */
102
  public function options_summary(&$categories, &$options) {
103
    // It is very important to call the parent function here:
104
    parent::options_summary($categories, $options);
105

    
106
    $categories['context'] = array(
107
      'title' => t('Context settings'),
108
      'column' => 'second',
109
      'build' => array(
110
        '#weight' => -10,
111
      ),
112
    );
113

    
114
    $admin_title = $this->get_option('admin_title');
115
    if (empty($admin_title)) {
116
      $admin_title = t('Use view name');
117
    }
118

    
119
    if (drupal_strlen($admin_title) > 16) {
120
      $admin_title = drupal_substr($admin_title, 0, 16) . '...';
121
    }
122

    
123
    $options['admin_title'] = array(
124
      'category' => 'context',
125
      'title' => t('Admin title'),
126
      'value' => $admin_title,
127
    );
128

    
129
    $options['inherit_panels_path'] = array(
130
      'category' => 'context',
131
      'title' => t('Use Panel path'),
132
      'value' => $this->get_option('inherit_panels_path') ? t('Yes') : t('No'),
133
    );
134

    
135
    $options['argument_input'] = array(
136
      'category' => 'context',
137
      'title' => t('Argument input'),
138
      'value' => t('Edit'),
139
    );
140
  }
141

    
142
  /**
143
   * Provide the default form for setting options.
144
   */
145
  public function options_form(&$form, &$form_state) {
146
    // It is very important to call the parent function here:
147
    parent::options_form($form, $form_state);
148
    switch ($form_state['section']) {
149
      case 'row_plugin':
150
        // This just overwrites the existing row_plugin which is using the wrong options.
151
        $form['row_plugin']['#options'] = views_fetch_plugin_names('row', 'normal', array($this->view->base_table));
152
        break;
153

    
154
      case 'admin_title':
155
        $form['#title'] .= t('Administrative title');
156

    
157
        $form['admin_title'] = array(
158
          '#type' => 'textfield',
159
          '#default_value' => $this->get_option('admin_title'),
160
          '#description' => t('This is the title that will appear for this view context in the configure context dialog. If left blank, the view name will be used.'),
161
        );
162
        break;
163

    
164
      case 'inherit_panels_path':
165
        $form['#title'] .= t('Inherit path from panel display');
166

    
167
        $form['inherit_panels_path'] = array(
168
          '#type' => 'select',
169
          '#options' => array(1 => t('Yes'), 0 => t('No')),
170
          '#default_value' => $this->get_option('inherit_panels_path'),
171
          '#description' => t('If yes, all links generated by Views, such as more links, summary links, and exposed input links will go to the panels display path, not the view, if the display has a path.'),
172
        );
173
        break;
174

    
175
      case 'argument_input':
176
        $form['#title'] .= t('Choose the data source for view arguments');
177
        $argument_input = $this->get_argument_input();
178
        ctools_include('context');
179
        ctools_include('dependent');
180
        $form['argument_input']['#tree'] = TRUE;
181

    
182
        $converters = ctools_context_get_all_converters();
183
        ksort($converters);
184

    
185
        foreach ($argument_input as $id => $argument) {
186
          $form['argument_input'][$id] = array(
187
            '#tree' => TRUE,
188
          );
189

    
190
          $safe = str_replace(array('][', '_', ' ', ':'), '-', $id);
191
          $type_id = 'edit-argument-input-' . $safe;
192

    
193
          $form['argument_input'][$id]['type'] = array(
194
            '#type' => 'select',
195
            '#options' => array(
196
              'none' => t('No argument'),
197
              'context' => t('From context'),
198
            ),
199
            '#id' => $type_id,
200
            '#title' => t('@arg source', array('@arg' => $argument['name'])),
201
            '#default_value' => $argument['type'],
202
          );
203

    
204
          $form['argument_input'][$id]['context'] = array(
205
            '#type' => 'select',
206
            '#title' => t('Required context'),
207
            '#description' => t('If "From context" is selected, which type of context to use.'),
208
            '#default_value' => $argument['context'],
209
            '#options' => $converters,
210
            '#dependency' => array($type_id => array('context')),
211
          );
212

    
213
          $form['argument_input'][$id]['context_optional'] = array(
214
            '#type' => 'checkbox',
215
            '#title' => t('Context is optional'),
216
            '#description' => t('This context need not be present for the pane to function. If you plan to use this, ensure that the argument handler can handle empty values gracefully.'),
217
            '#default_value' => $argument['context_optional'],
218
            '#dependency' => array($type_id => array('context')),
219
          );
220
        }
221
        break;
222
    }
223
  }
224

    
225
  /**
226
   * Perform any necessary changes to the form values prior to storage.
227
   * There is no need for this function to actually store the data.
228
   */
229
  public function options_submit(&$form, &$form_state) {
230
    // It is very important to call the parent function here:
231
    parent::options_submit($form, $form_state);
232
    switch ($form_state['section']) {
233
      case 'admin_title':
234
      case 'argument_input':
235
      case 'inherit_panels_path':
236
        $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
237
        break;
238
    }
239
  }
240

    
241
  /**
242
   * Adjust the array of argument input to match the current list of
243
   * arguments available for this display. This ensures that changing
244
   * the arguments doesn't cause the argument input field to just
245
   * break.
246
   */
247
  public function get_argument_input() {
248
    $arguments = $this->get_option('argument_input');
249
    $handlers = $this->get_handlers('argument');
250

    
251
    // We use a separate output so as to seamlessly discard info for
252
    // arguments that no longer exist.
253
    $output = array();
254

    
255
    foreach ($handlers as $id => $handler) {
256
      if (empty($arguments[$id])) {
257
        $output[$id] = array(
258
          'type' => 'none',
259
          'context' => 'any',
260
          'context_optional' => FALSE,
261
          'name' => $handler->ui_name(),
262
        );
263
      }
264
      else {
265
        $output[$id] = $arguments[$id];
266
        $output[$id]['name'] = $handler->ui_name();
267
      }
268
    }
269

    
270
    return $output;
271
  }
272

    
273

    
274
  public function get_path() {
275
    if ($this->get_option('link_display') == 'custom_url' && $override_path = $this->get_option('link_url')) {
276
      return $override_path;
277
    }
278
    if ($this->get_option('inherit_panels_path')) {
279
      return $_GET['q'];
280
    }
281
    return parent::get_path();
282
  }
283

    
284
}