Projet

Général

Profil

Paste
Télécharger (5,25 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panels / plugins / views / panels_views_plugin_row_fields.inc @ 64156087

1
<?php
2
/**
3
 * @file
4
 * Contains the base row style plugin.
5
 */
6

    
7
/**
8
 * The basic 'fields' row plugin.
9
 *
10
 * This displays fields one after another, giving options for inline
11
 * or not.
12
 *
13
 * @ingroup views_row_plugins
14
 */
15
class panels_views_plugin_row_fields extends views_plugin_row_fields {
16
  function option_definition() {
17
    $options = parent::option_definition();
18

    
19
    $options['layout'] = array('default' => 'twocol');
20
    $options['regions'] = array('default' => array());
21

    
22
    return $options;
23
  }
24

    
25
  /**
26
   * Provide a form for setting options.
27
   */
28
  function options_form(&$form, &$form_state) {
29
    parent::options_form($form, $form_state);
30

    
31
    ctools_include('plugins', 'panels');
32
    $layouts = panels_get_layouts();
33
    $options = array();
34
    foreach ($layouts as $name => $layout) {
35
      if (empty($layout['builder'])) {
36
        $options[$name] = $layout['title'];
37
      }
38
      if ($name == $this->options['layout']) {
39
        $current_layout = $layout;
40
      }
41
    }
42

    
43
    $form['layout'] = array(
44
      '#prefix' => '<div class="container-inline">',
45
      '#type' => 'select',
46
      '#options' => $options,
47
      '#title' => t('Panel layout'),
48
      '#default_value' => $this->options['layout'],
49
    );
50

    
51
    $form['change'] = array(
52
      '#type' => 'submit',
53
      '#value' => t('Change'),
54
      '#submit' => array('panels_change_layout_button'),
55
      '#suffix' => '</div>',
56
    );
57

    
58
    if (!empty($current_layout)) {
59
      $fields = $this->display->handler->get_field_labels();
60
      $regions = panels_get_regions($current_layout, panels_new_display());
61
      foreach ($fields as $id => $title) {
62
        $form['regions'][$id] = array(
63
          '#type' => 'select',
64
          '#title' => $title,
65
          '#options' => $regions,
66
        );
67
        if (!empty($this->options['regions'][$id]) && !empty($regions[$this->options['regions'][$id]])) {
68
          $form['regions'][$id]['#default_value'] = $this->options['regions'][$id];
69
        }
70
      }
71
    }
72
  }
73

    
74
  /**
75
   * Perform any necessary changes to the form values prior to storage.
76
   * There is no need for this function to actually store the data.
77
   */
78
  function options_submit(&$form, &$form_state) {
79
    $form_state['values']['row_options']['inline'] = array_filter($form_state['values']['row_options']['inline']);
80
  }
81

    
82
  /**
83
   * Render a row object. This usually passes through to a theme template
84
   * of some form, but not always.
85
   */
86
  function render($row) {
87
    ctools_include('plugins', 'panels');
88
    $layout = panels_get_layout($this->options['layout']);
89
    if (!$layout) {
90
      // Fall back to normal behavior if the layout is somehow invalid. This
91
      // can happen if the layout was removed, for example.
92
      return theme($this->theme_functions(), array('view' => $this->view, 'options' => $this->options, 'row' => $row));
93

    
94
    }
95

    
96
    // Store a backup copy of the array because we're going to be screwing
97
    // with this a lot.
98
    $fields = $this->view->field;
99
    unset($this->view->field);
100

    
101
    $meta = 'standard';
102
    // This row style gets run many times; only run this code once.
103
    if (empty($this->region_fields)) {
104
      $this->region_fields = array();
105
      $regions = panels_get_regions($layout, panels_new_display());
106

    
107
      // Ensure each region has an empty array.
108
      foreach ($regions as $region_id => $name) {
109
        if (empty($default_region)) {
110
          $default_region = $region_id;
111
        }
112

    
113
        $this->region_fields[$region_id] = array();
114
      }
115

    
116

    
117
      // Go through all our fields and place them in regions according to the
118
      // settings.
119
      foreach ($fields as $id => $field) {
120
        $region_id = ''; // ensure we don't accidentlly use the last field's region.
121
        if (!empty($this->options['regions'][$id]) && !empty($regions[$this->options['regions'][$id]])) {
122
          $region_id = $this->options['regions'][$id];
123
        }
124
        else {
125
          // Fallback to putting unknown fields into the first region.
126
          $region_id = $default_region;
127
        }
128

    
129
        // Ensure this works in PHP4 by keeping the reference.
130
        $this->region_fields[$region_id][$id] = &$fields[$id];
131
      }
132

    
133
      // We don't need to set 'inline' for every record, so we do it inside
134
      // this loop. We do need to set inline if we are in the live preview
135
      // so that the CSS will get transmitted via javascript:
136
      $meta = !empty($this->view->live_preview) ? 'inline' : 'standard';
137
    }
138

    
139
    // Now that we have distributed our fields, go through the regions and
140
    // render them into the content array.
141
    foreach ($this->region_fields as $region_id => $fields_list) {
142
      $this->view->field = $fields_list;
143
      $content[$region_id] = theme($this->theme_functions(), array('view' => $this->view, 'options' => $this->options, 'row' => $row));
144
    }
145

    
146
    // Restore our $fields array.
147
    $this->view->field = $fields;
148

    
149
    // Now that we have a rendered content array, render it.
150
    return panels_print_layout($layout, $content, $meta);
151
  }
152

    
153
}
154

    
155
/**
156
 * Override handler for views_ui_edit_display_form.
157
 */
158
function panels_change_layout_button($form, &$form_state) {
159
  $display = &$form_state['view']->display[$form_state['display_id']];
160
  $display->handler->options_submit($form, $form_state);
161

    
162
  views_ui_cache_set($form_state['view']);
163
  $form_state['rerender'] = TRUE;
164
  $form_state['rebuild'] = TRUE;
165
}