View source
<?php
class views_plugin_ds_fields_view extends views_plugin_row {
function init(&$view, &$display, $options = NULL) {
parent::init($view, $display, $options);
$this->base_table = $view->base_table;
if ($this->base_table == 'apachesolr') {
$this->base_table = 'node';
}
$this->base_field = $this
->ds_views_3_support();
}
function ds_views_3_support() {
$base_table_fields = array(
'node' => 'nid',
'comment' => 'cid',
'users' => 'uid',
'apachesolr' => 'nid',
'taxonomy_term_data' => 'tid',
'file_managed' => 'fid',
'micro' => 'mid',
'drealty_listing' => 'id',
'commerce_product' => 'product_id',
'commerce_line_item' => 'line_item_id',
);
return isset($base_table_fields[$this->base_table]) ? $base_table_fields[$this->base_table] : 'nid';
}
function option_definition() {
$options = parent::option_definition();
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$url = url('admin/structure/ds/vd', array(
'absolute' => TRUE,
));
$link_url = l($url, $url, array(
'alias' => TRUE,
));
$form['info'] = array(
'#markup' => t('The layout selection and positioning of fields happens at !url.', array(
'!url' => $link_url,
)),
);
}
}
function template_preprocess_ds_row_fields(&$vars) {
static $row_layout = array();
$bundle = $vars['view']->name . '-' . $vars['view']->current_display . '-fields';
if (!isset($row_layout[$bundle])) {
$row_layout[$bundle] = ds_get_layout('ds_views', $bundle, 'default');
if ($row_layout[$bundle]) {
drupal_add_css($row_layout[$bundle]['path'] . '/' . $row_layout[$bundle]['layout'] . '.css');
}
}
if (isset($row_layout[$bundle])) {
$view = $vars['view'];
$layout = $row_layout[$bundle];
if (!$layout) {
return;
}
$hide_empty_regions = $layout['settings']['hide_empty_regions'];
$vars['classes_array'] = array();
$vars['classes_array'][] = strtr($bundle, '_', '-');
$vars['theme_hook_suggestions'][] = $layout['layout'];
$vars['theme_hook_suggestions'][] = $layout['layout'] . '__ds_views_' . $bundle;
$row_index = $view->row_index;
foreach ($layout['regions'] as $region_name => $region) {
$region_content = '';
if (isset($layout['settings']['regions'][$region_name])) {
foreach ($layout['settings']['regions'][$region_name] as $key => $field) {
if ($view->field[$field]->options['hide_empty'] && empty($view->style_plugin->rendered_fields[$row_index][$field])) {
continue;
}
$region_content .= '<div class="views-field-' . $field . '">';
if (!empty($view->field[$field]->options['label'])) {
$region_content .= '<div class="field-label">';
$region_content .= check_plain($view->field[$field]->options['label']);
if ($view->field[$field]->options['element_label_colon']) {
$region_content .= ':';
}
$region_content .= '</div>';
}
$region_content .= $view->style_plugin->rendered_fields[$row_index][$field];
$region_content .= '</div>';
}
}
$vars[$region_name] = $region_content;
if ($hide_empty_regions && empty($vars[$region_name]) && empty($layout['flexible'])) {
$vars[$region_name] = FALSE;
}
elseif (empty($vars[$region_name])) {
$vars[$region_name] = ' ';
}
$vars[$region_name . '_classes'] = !empty($layout['settings']['classes'][$region_name]) ? ' ' . implode(' ', $layout['settings']['classes'][$region_name]) : '';
}
}
}