5 * Contains the base row style plugin.
9 * The basic 'fields' row plugin
11 * This displays fields one after another, giving options for inline
14 * @ingroup views_row_plugins
16 class panels_views_plugin_row_fields
extends views_plugin_row
{
17 function option_definition() {
18 $options = parent
::option_definition();
20 $options['inline'] = array('default' => array());
21 $options['separator'] = array('default' => '');
22 $options['hide_empty'] = array('default' => FALSE
);
23 $options['layout'] = array('default' => 'twocol');
24 $options['regions'] = array('default' => array());
30 * Provide a form for setting options.
32 function options_form(&$form, &$form_state) {
33 $fields = $this->display
->handler
->get_field_labels();
35 if (empty($this->options
['inline'])) {
36 $this->options
['inline'] = array();
39 $form['inline'] = array(
40 '#type' => 'checkboxes',
41 '#title' => t('Inline fields'),
42 '#options' => $fields,
43 '#default_value' => $this->options
['inline'],
44 '#description' => t('Inline fields will be displayed next to each other rather than one after another.'),
47 $form['separator'] = array(
48 '#title' => t('Separator'),
49 '#type' => 'textfield',
51 '#default_value' => isset($this->options
['separator']) ?
$this->options
['separator'] : '',
52 '#description' => t('The separator may be placed between inline fields to keep them from squishing up next to each other. You can use HTML in this field.'),
55 $form['hide_empty'] = array(
56 '#type' => 'checkbox',
57 '#title' => t('Hide empty fields'),
58 '#default_value' => $this->options
['hide_empty'],
59 '#description' => t('Do not display fields, labels or markup for fields that are empty.'),
62 ctools_include('plugins', 'panels');
63 $layouts = panels_get_layouts();
65 foreach ($layouts as
$name => $layout) {
66 if (empty($layout['builder'])) {
67 $options[$name] = $layout['title'];
69 if ($name == $this->options
['layout']) {
70 $current_layout = $layout;
74 $form['layout'] = array(
75 '#prefix' => '<div class="container-inline">',
77 '#options' => $options,
78 '#title' => t('Panel layout'),
79 '#default_value' => $this->options
['layout'],
82 $form['change'] = array(
84 '#value' => t('Change'),
85 '#submit' => array('panels_change_layout_button'),
86 '#suffix' => '</div>',
89 if (!empty($current_layout)) {
90 $regions = panels_get_regions($current_layout, panels_new_display());
91 foreach ($fields as
$id => $title) {
92 $form['regions'][$id] = array(
95 '#options' => $regions,
97 if (!empty($this->options
['regions'][$id]) && !empty($regions[$this->options
['regions'][$id]])) {
98 $form['regions'][$id]['#default_value'] = $this->options
['regions'][$id];
105 * Perform any necessary changes to the form values prior to storage.
106 * There is no need for this function to actually store the data.
108 function options_submit($form, &$form_state) {
109 $form_state['values']['row_options']['inline'] = array_filter($form_state['values']['row_options']['inline']);
113 * Render a row object. This usually passes through to a theme template
114 * of some form, but not always.
116 function render($row) {
117 ctools_include('plugins', 'panels');
118 $layout = panels_get_layout($this->options
['layout']);
120 // Fall back to normal behavior if the layout is somehow invalid. This
121 // can happen if the layout was removed, for example.
122 return theme($this->theme_functions(), array('view' => view
, 'options' => $this->options
, 'row' => $row, 'field_alias' => $this->field_alias
));
125 // Store a backup copy of the array because we're going to be screwing
127 $fields = $this->view
->field
;
128 unset($this->view
->field
);
131 // This row style gets run many times; only run this code once.
132 if (empty($this->region_fields
)) {
133 $this->region_fields
= array();
134 $regions = panels_get_regions($layout, panels_new_display());
136 // Ensure each region has an empty array.
137 foreach ($regions as
$region_id => $name) {
138 if (empty($default_region)) {
139 $default_region = $region_id;
142 $this->region_fields
[$region_id] = array();
146 // Go through all our fields and place them in regions according to the
148 foreach ($fields as
$id => $field) {
149 $region_id = ''; // ensure we don't accidentlly use the last field's region.
150 if (!empty($this->options
['regions'][$id]) && !empty($regions[$this->options
['regions'][$id]])) {
151 $region_id = $this->options
['regions'][$id];
154 // Fallback to putting unknown fields into the first region.
155 $region_id = $default_region;
158 // Ensure this works in PHP4 by keeping the reference.
159 $this->region_fields
[$region_id][$id] = &$fields[$id];
162 // We don't need to set 'inline' for every record, so we do it inside
163 // this loop. We do need to set inline if we are in the live preview
164 // so that the CSS will get transmitted via javascript:
165 $meta = !empty($this->view
->live_preview
) ?
'inline' : 'standard';
168 // Now that we have distributed our fields, go through the regions and
169 // render them into the content array.
170 foreach ($this->region_fields as
$region_id => $fields) {
171 $this->view
->field
= $fields;
172 $content[$region_id] = theme($this->theme_functions(), array('view' => $this->view
, 'options' => $this->options
, 'row' => $row));
175 // Restore our $fields array.
176 $view->field
= $fields;
178 // Now that we have a rendered content array, render it.
179 return panels_print_layout($layout, $content, $meta);
184 * Override handler for views_ui_edit_display_form
186 function panels_change_layout_button($form, &$form_state) {
187 $display = &$form_state['view']->display
[$form_state['display_id']];
188 $display->handler
->options_submit($form, $form_state);
190 views_ui_cache_set($form_state['view']);
191 $form_state['rerender'] = TRUE
;
192 $form_state['rebuild'] = TRUE
;