Projet

Général

Profil

Paste
Télécharger (1,85 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / field_collection / views / field_collection_handler_relationship.inc @ 5e632cae

1
<?php
2

    
3
/**
4
 * @file
5
 * Provide relationship handler for field collection fields.
6
 */
7

    
8
class field_collection_handler_relationship extends views_handler_relationship {
9

    
10
  function option_definition() {
11
    $options = parent::option_definition();
12
    $options['delta'] = array('default' => -1);
13

    
14
    return $options;
15
  }
16

    
17
  /**
18
   * Add a delta selector for multiple fields.
19
   */
20
  function options_form(&$form, &$form_state) {
21
    parent::options_form($form, $form_state);
22

    
23
    $field = field_info_field($this->definition['field_name']);
24

    
25
    // Only add the delta selector if the field is multiple.
26
    if ($field['cardinality']) {
27
      $max_delta = ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) ? 10 : $field['cardinality'];
28

    
29
      $options = array('-1' => t('All'));
30
      for ($i = 0; $i < $max_delta; $i++) {
31
        $options[$i] = $i + 1;
32
      }
33
      $form['delta'] = array(
34
        '#type' => 'select',
35
        '#options' => $options,
36
        '#default_value' => $this->options['delta'],
37
        '#title' => t('Delta'),
38
        '#description' => t('The delta allows you to select which item in a multiple value field to key the relationship off of. Select "1" to use the first item, "2" for the second item, and so on. If you select "All", each item in the field will create a new row, which may appear to cause duplicates.'),
39
      );
40
    }
41
  }
42

    
43
  function ensure_my_table() {
44
    $field = field_info_field($this->definition['field_name']);
45

    
46
    if (!isset($this->table_alias)) {
47
      $join = $this->get_join();
48
      if ($this->options['delta'] != -1 && $field['cardinality']) {
49
        $join->extra[] = array(
50
          'field' => 'delta',
51
          'value' => $this->options['delta'],
52
          'numeric' => TRUE,
53
        );
54
      }
55
      $this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
56
    }
57
    return $this->table_alias;
58
  }
59

    
60
}