View source
<?php
class panels_views_plugin_row_fields extends views_plugin_row_fields {
function option_definition() {
$options = parent::option_definition();
$options['layout'] = array(
'default' => 'twocol',
);
$options['regions'] = array(
'default' => array(),
);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
ctools_include('plugins', 'panels');
$layouts = panels_get_layouts();
$options = array();
foreach ($layouts as $name => $layout) {
if (empty($layout['builder'])) {
$options[$name] = $layout['title'];
}
if ($name == $this->options['layout']) {
$current_layout = $layout;
}
}
$form['layout'] = array(
'#prefix' => '<div class="container-inline">',
'#type' => 'select',
'#options' => $options,
'#title' => t('Panel layout'),
'#default_value' => $this->options['layout'],
);
$form['change'] = array(
'#type' => 'submit',
'#value' => t('Change'),
'#submit' => array(
'panels_change_layout_button',
),
'#suffix' => '</div>',
);
if (!empty($current_layout)) {
$fields = $this->display->handler
->get_field_labels();
$regions = panels_get_regions($current_layout, panels_new_display());
foreach ($fields as $id => $title) {
$form['regions'][$id] = array(
'#type' => 'select',
'#title' => $title,
'#options' => $regions,
);
if (!empty($this->options['regions'][$id]) && !empty($regions[$this->options['regions'][$id]])) {
$form['regions'][$id]['#default_value'] = $this->options['regions'][$id];
}
}
}
}
function options_submit(&$form, &$form_state) {
$form_state['values']['row_options']['inline'] = array_filter($form_state['values']['row_options']['inline']);
}
function render($row) {
ctools_include('plugins', 'panels');
$layout = panels_get_layout($this->options['layout']);
if (!$layout) {
return theme($this
->theme_functions(), array(
'view' => $this->view,
'options' => $this->options,
'row' => $row,
));
}
$fields = $this->view->field;
unset($this->view->field);
$meta = 'standard';
if (empty($this->region_fields)) {
$this->region_fields = array();
$regions = panels_get_regions($layout, panels_new_display());
foreach ($regions as $region_id => $name) {
if (empty($default_region)) {
$default_region = $region_id;
}
$this->region_fields[$region_id] = array();
}
foreach ($fields as $id => $field) {
$region_id = '';
if (!empty($this->options['regions'][$id]) && !empty($regions[$this->options['regions'][$id]])) {
$region_id = $this->options['regions'][$id];
}
else {
$region_id = $default_region;
}
$this->region_fields[$region_id][$id] =& $fields[$id];
}
$meta = !empty($this->view->live_preview) ? 'inline' : 'standard';
}
foreach ($this->region_fields as $region_id => $fields_list) {
$this->view->field = $fields_list;
$content[$region_id] = theme($this
->theme_functions(), array(
'view' => $this->view,
'options' => $this->options,
'row' => $row,
));
}
$this->view->field = $fields;
return panels_print_layout($layout, $content, $meta);
}
}
function panels_change_layout_button($form, &$form_state) {
$display =& $form_state['view']->display[$form_state['display_id']];
$display->handler
->options_submit($form, $form_state);
views_ui_cache_set($form_state['view']);
$form_state['rerender'] = TRUE;
$form_state['rebuild'] = TRUE;
}