Projet

Général

Profil

Paste
Télécharger (3,38 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / addressfield / views / addressfield.views.inc @ fc3d89c3

1
<?php
2

    
3
/**
4
 * Implements hook_field_views_data().
5
 */
6
function addressfield_field_views_data($field) {
7
  $data = field_views_field_default_views_data($field);
8

    
9
  // Add a filter handler for countries.
10
  $key = key($field['storage']['details']);
11
  foreach ($field['storage']['details'][$key] as $type => $tables) {
12
    foreach ($tables as $table_name => $columns) {
13
      if (!isset($columns['country'])) {
14
        continue;
15
      }
16

    
17
      $column_real_name = $columns['country'];
18
      if (!isset($data[$table_name][$column_real_name]['filter'])) {
19
        continue;
20
      }
21

    
22
      $data[$table_name][$column_real_name]['filter']['handler'] = 'addressfield_views_handler_filter_country';
23
    }
24
  }
25

    
26
  // Only expose these components as Views field handlers.
27
  $implemented = array(
28
    'country' => 'addressfield_views_handler_field_country',
29
    'administrative_area' => 'addressfield_views_handler_field_administrative_area',
30
    'sub_administrative_area' => 'views_handler_field',
31
    'dependent_locality' => 'views_handler_field',
32
    'locality' => 'views_handler_field',
33
    'postal_code' => 'views_handler_field',
34
    'thoroughfare' => 'views_handler_field',
35
    'premise' => 'views_handler_field',
36
    'sub_premise' => 'views_handler_field',
37
    'organisation_name' => 'views_handler_field',
38
    'name_line' => 'views_handler_field',
39
    'first_name' => 'views_handler_field',
40
    'last_name' => 'views_handler_field',
41
    'data' => 'views_handler_field_serialized',
42
  );
43

    
44
  // Get the translated field information.
45
  $properties = addressfield_data_property_info();
46

    
47
  // Iterate over addressfield defined tables.
48
  foreach ($data as &$table) {
49
    // Make sure the parent Views field (addressfield) is defined.
50
    if (isset($table[$field['field_name']]['field'])) {
51
      // Use the parent field definition as a template for component columns.
52
      $field_def = $table[$field['field_name']]['field'];
53

    
54
      // Remove 'additional fields' from the field definition. We don't
55
      // necessarily want all our sibling columns.
56
      unset($field_def['additional fields']);
57

    
58
      // Define the valid columns.
59
      $valid_columns = array();
60
      foreach ($implemented as $implement => $handler) {
61
        $column_name = $field['field_name'] . '_' . $implement;
62
        $valid_columns[$column_name] = $handler;
63
      }
64

    
65
      // Iterate over the addressfield components.
66
      foreach ($table as $column_name => &$column) {
67
        if (empty($column['field']) && isset($valid_columns[$column_name])) {
68
          // Assign the default component definition.
69
          $column['field'] = $field_def;
70
          $column['field']['real field'] = $column_name;
71
          $column['field']['handler'] = $valid_columns[$column_name];
72

    
73
          // Assign human-friendly field labels for addressfield components.
74
          $field_labels = field_views_field_label($field['field_name']);
75
          $field_label = array_shift($field_labels);
76
          $property = str_replace($field_def['field_name'] . '_', '', $column_name);
77

    
78
          if (!empty($properties[$property])) {
79
            $property_label = $properties[$property]['label'];
80

    
81
            $title = t('@field-label - @property-label', array(
82
              '@field-label' => $field_label,
83
              '@property-label' => $property_label,
84
            ));
85

    
86
            $column['title'] = $title;
87
            $column['title short'] = $title;
88
          }
89
        }
90
      }
91
    }
92
  }
93

    
94
  return $data;
95
}