Projet

Général

Profil

Paste
Télécharger (4,99 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ds / views / views_plugin_ds_fields_view.inc @ 87dbc3bf

1
<?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
    );
45
    return isset($base_table_fields[$this->base_table]) ? $base_table_fields[$this->base_table] : 'nid';
46
  }
47

    
48
  function option_definition() {
49
    $options = parent::option_definition();
50
    return $options;
51
  }
52

    
53
  function options_form(&$form, &$form_state) {
54
    parent::options_form($form, $form_state);
55

    
56
    $url = url('admin/structure/ds/vd', array('absolute' => TRUE));
57
    $link_url = l($url, $url, array('alias' => TRUE));
58
    $form['info'] = array(
59
      '#markup' => t('The layout selection and positioning of fields happens at !url.', array('!url' => $link_url)),
60
    );
61
  }
62
}
63

    
64
/**
65
 * Preprocess function for ds_fields_view().
66
 */
67
function template_preprocess_ds_row_fields(&$vars) {
68
  static $row_layout = array();
69

    
70
  // Check if we have layout configured for this bundle.
71
  $bundle = $vars['view']->name . '-' . $vars['view']->current_display . '-fields';
72
  if (!isset($row_layout[$bundle])) {
73

    
74
    // Register the layout, even if when it returns false.
75
    $row_layout[$bundle] = ds_get_layout('ds_views', $bundle, 'default');
76

    
77
    // Add css.
78
    if ($row_layout[$bundle]) {
79
      drupal_add_css($row_layout[$bundle]['path'] . '/' . $row_layout[$bundle]['layout'] . '.css');
80
    }
81
  }
82

    
83
  // Render the views fields into the template layout.
84
  // This code is more or less copied from ds_entity_variables().
85
  if (isset($row_layout[$bundle])) {
86

    
87
    $view = $vars['view'];
88
    $layout = $row_layout[$bundle];
89
    if (!$layout) {
90
      return;
91
    }
92

    
93
    // Classes array.
94
    $vars['classes_array'] = array();
95
    $vars['classes_array'][] = strtr($bundle, '_', '-');
96

    
97
    // Template suggestions.
98
    $vars['theme_hook_suggestions'][] = $layout['layout'];
99
    $vars['theme_hook_suggestions'][] = $layout['layout'] . '__ds_views_' . $bundle;
100

    
101
    // Row index.
102
    $row_index = $view->row_index;
103

    
104
    // Layout wrapper.
105
    $vars['layout_wrapper'] = isset($layout['settings']['layout_wrapper']) ? $layout['settings']['layout_wrapper'] : 'div';
106

    
107
    // Layout attributes
108
    if (!empty($layout['settings']['layout_attributes'])) {
109
      $vars['layout_attributes'] = ' ' . $layout['settings']['layout_attributes'];
110
    }
111
    else {
112
      $vars['layout_attributes'] = '';
113
    }
114

    
115
    // Create region variables based on the layout settings.
116
    foreach ($layout['regions'] as $region_name => $region) {
117

    
118
      // Create the region content.
119
      $region_content = '';
120
      if (isset($layout['settings']['regions'][$region_name])) {
121
        foreach ($layout['settings']['regions'][$region_name] as $key => $field) {
122
          // Do not render the field when empty and configured to be hidden.
123
          if ($view->field[$field]->options['hide_empty'] && empty($view->style_plugin->rendered_fields[$row_index][$field])) {
124
            continue;
125
          }
126
          $region_content .= '<div class="views-field-' . $field . '">';
127
          if (!empty($view->field[$field]->options['label'])) {
128
            $region_content .= '<div class="field-label">';
129
            $region_content .= check_plain($view->field[$field]->options['label']);
130
            if ($view->field[$field]->options['element_label_colon']) {
131
              $region_content .= ':';
132
            }
133
            $region_content .= '</div>';
134
          }
135
          $region_content .= $view->style_plugin->rendered_fields[$row_index][$field];
136
          $region_content .= '</div>';
137
        }
138
      }
139
      $vars[$region_name] = $region_content;
140

    
141
      // Region wrapper.
142
      $vars[$region_name . '_wrapper'] = isset($layout['settings']['wrappers'][$region_name]) ? $layout['settings']['wrappers'][$region_name] : 'div';
143

    
144
      // Add extras classes to the region.
145
      $vars[$region_name . '_classes'] = !empty($layout['settings']['classes'][$region_name]) ? ' ' . implode(' ', $layout['settings']['classes'][$region_name]) : '';
146
    }
147
  }
148
}