1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Provides the Display Suite views fields style plugin.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Plugin which defines the view mode on the resulting entity object.
|
10 |
|
|
*/
|
11 |
|
|
class views_plugin_ds_fields_view extends views_plugin_row {
|
12 |
|
|
|
13 |
|
|
function init(&$view, &$display, $options = NULL) {
|
14 |
|
|
parent::init($view, $display, $options);
|
15 |
|
|
$this->base_table = $view->base_table;
|
16 |
|
|
// Special case for apachesolr_views.
|
17 |
|
|
if ($this->base_table == 'apachesolr') {
|
18 |
|
|
$this->base_table = 'node';
|
19 |
|
|
}
|
20 |
|
|
$this->base_field = $this->ds_views_3_support();
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
// Return base_field based on base_table. It might not be
|
24 |
|
|
// the cleanest solution, it's the fastest though.
|
25 |
|
|
function ds_views_3_support() {
|
26 |
|
|
if (strpos($this->base_table, 'eck_') === 0) {
|
27 |
|
|
// Base tables of entities created by entity construction kit (eck)
|
28 |
|
|
// are prefixed with 'eck_' and the base field is always 'id'.
|
29 |
|
|
return 'id';
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
$base_table_fields = array(
|
33 |
|
|
'node' => 'nid',
|
34 |
|
|
'comment' => 'cid',
|
35 |
|
|
'users' => 'uid',
|
36 |
|
|
'apachesolr' => 'nid',
|
37 |
|
|
'taxonomy_term_data' => 'tid',
|
38 |
|
|
'file_managed' => 'fid',
|
39 |
|
|
'micro' => 'mid',
|
40 |
|
|
'drealty_listing' => 'id',
|
41 |
|
|
'commerce_product' => 'product_id',
|
42 |
|
|
'commerce_line_item' => 'line_item_id',
|
43 |
|
|
'civicrm_event' => 'id',
|
44 |
6e9292aa
|
Assos Assos
|
'field_collection_item' => 'item_id',
|
45 |
85ad3d82
|
Assos Assos
|
);
|
46 |
|
|
return isset($base_table_fields[$this->base_table]) ? $base_table_fields[$this->base_table] : 'nid';
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
function option_definition() {
|
50 |
|
|
$options = parent::option_definition();
|
51 |
|
|
return $options;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
function options_form(&$form, &$form_state) {
|
55 |
|
|
parent::options_form($form, $form_state);
|
56 |
|
|
|
57 |
|
|
$url = url('admin/structure/ds/vd', array('absolute' => TRUE));
|
58 |
|
|
$link_url = l($url, $url, array('alias' => TRUE));
|
59 |
|
|
$form['info'] = array(
|
60 |
|
|
'#markup' => t('The layout selection and positioning of fields happens at !url.', array('!url' => $link_url)),
|
61 |
|
|
);
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* Preprocess function for ds_fields_view().
|
67 |
|
|
*/
|
68 |
|
|
function template_preprocess_ds_row_fields(&$vars) {
|
69 |
|
|
static $row_layout = array();
|
70 |
|
|
|
71 |
|
|
// Check if we have layout configured for this bundle.
|
72 |
|
|
$bundle = $vars['view']->name . '-' . $vars['view']->current_display . '-fields';
|
73 |
|
|
if (!isset($row_layout[$bundle])) {
|
74 |
|
|
|
75 |
|
|
// Register the layout, even if when it returns false.
|
76 |
|
|
$row_layout[$bundle] = ds_get_layout('ds_views', $bundle, 'default');
|
77 |
|
|
|
78 |
|
|
// Add css.
|
79 |
|
|
if ($row_layout[$bundle]) {
|
80 |
|
|
drupal_add_css($row_layout[$bundle]['path'] . '/' . $row_layout[$bundle]['layout'] . '.css');
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
// Render the views fields into the template layout.
|
85 |
|
|
// This code is more or less copied from ds_entity_variables().
|
86 |
|
|
if (isset($row_layout[$bundle])) {
|
87 |
|
|
|
88 |
|
|
$view = $vars['view'];
|
89 |
|
|
$layout = $row_layout[$bundle];
|
90 |
|
|
if (!$layout) {
|
91 |
|
|
return;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
// Classes array.
|
95 |
|
|
$vars['classes_array'] = array();
|
96 |
|
|
$vars['classes_array'][] = strtr($bundle, '_', '-');
|
97 |
|
|
|
98 |
|
|
// Template suggestions.
|
99 |
|
|
$vars['theme_hook_suggestions'][] = $layout['layout'];
|
100 |
|
|
$vars['theme_hook_suggestions'][] = $layout['layout'] . '__ds_views_' . $bundle;
|
101 |
|
|
|
102 |
|
|
// Row index.
|
103 |
|
|
$row_index = $view->row_index;
|
104 |
|
|
|
105 |
|
|
// Layout wrapper.
|
106 |
|
|
$vars['layout_wrapper'] = isset($layout['settings']['layout_wrapper']) ? $layout['settings']['layout_wrapper'] : 'div';
|
107 |
|
|
|
108 |
|
|
// Layout attributes
|
109 |
|
|
if (!empty($layout['settings']['layout_attributes'])) {
|
110 |
|
|
$vars['layout_attributes'] = ' ' . $layout['settings']['layout_attributes'];
|
111 |
|
|
}
|
112 |
|
|
else {
|
113 |
|
|
$vars['layout_attributes'] = '';
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
// Create region variables based on the layout settings.
|
117 |
|
|
foreach ($layout['regions'] as $region_name => $region) {
|
118 |
|
|
|
119 |
|
|
// Create the region content.
|
120 |
|
|
$region_content = '';
|
121 |
|
|
if (isset($layout['settings']['regions'][$region_name])) {
|
122 |
|
|
foreach ($layout['settings']['regions'][$region_name] as $key => $field) {
|
123 |
|
|
// Do not render the field when empty and configured to be hidden.
|
124 |
|
|
if ($view->field[$field]->options['hide_empty'] && empty($view->style_plugin->rendered_fields[$row_index][$field])) {
|
125 |
|
|
continue;
|
126 |
|
|
}
|
127 |
|
|
$region_content .= '<div class="views-field-' . $field . '">';
|
128 |
|
|
if (!empty($view->field[$field]->options['label'])) {
|
129 |
|
|
$region_content .= '<div class="field-label">';
|
130 |
|
|
$region_content .= check_plain($view->field[$field]->options['label']);
|
131 |
|
|
if ($view->field[$field]->options['element_label_colon']) {
|
132 |
|
|
$region_content .= ':';
|
133 |
|
|
}
|
134 |
|
|
$region_content .= '</div>';
|
135 |
|
|
}
|
136 |
|
|
$region_content .= $view->style_plugin->rendered_fields[$row_index][$field];
|
137 |
|
|
$region_content .= '</div>';
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
|
|
$vars[$region_name] = $region_content;
|
141 |
|
|
|
142 |
|
|
// Region wrapper.
|
143 |
|
|
$vars[$region_name . '_wrapper'] = isset($layout['settings']['wrappers'][$region_name]) ? $layout['settings']['wrappers'][$region_name] : 'div';
|
144 |
|
|
|
145 |
|
|
// Add extras classes to the region.
|
146 |
|
|
$vars[$region_name . '_classes'] = !empty($layout['settings']['classes'][$region_name]) ? ' ' . implode(' ', $layout['settings']['classes'][$region_name]) : '';
|
147 |
|
|
}
|
148 |
|
|
}
|
149 |
|
|
} |