1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Defines a field handler that can display the administrative area name
|
5
|
* instead of the code.
|
6
|
*/
|
7
|
class addressfield_views_handler_field_administrative_area extends views_handler_field {
|
8
|
|
9
|
function query() {
|
10
|
parent::query();
|
11
|
|
12
|
$this->country_alias = $this->query->add_field($this->table_alias, $this->definition['field_name'] . '_country');
|
13
|
}
|
14
|
|
15
|
function option_definition() {
|
16
|
$options = parent::option_definition();
|
17
|
$options['display_name'] = array('default' => TRUE);
|
18
|
return $options;
|
19
|
}
|
20
|
|
21
|
function options_form(&$form, &$form_state) {
|
22
|
parent::options_form($form, $form_state);
|
23
|
|
24
|
$form['display_name'] = array(
|
25
|
'#type' => 'checkbox',
|
26
|
'#title' => t('Display the name of administrative area instead of the code.'),
|
27
|
'#default_value' => $this->options['display_name'],
|
28
|
);
|
29
|
}
|
30
|
|
31
|
function get_value($values, $field = NULL) {
|
32
|
$value = parent::get_value($values, $field);
|
33
|
|
34
|
// If we have a value for the field, look for the administrative area name in the
|
35
|
// Address Field options list array if specified.
|
36
|
if (!empty($value) && !empty($this->options['display_name'])) {
|
37
|
module_load_include('inc', 'addressfield', 'addressfield.administrative_areas');
|
38
|
$country = $values->{$this->country_alias};
|
39
|
$areas = addressfield_get_administrative_areas($country);
|
40
|
|
41
|
if (!empty($areas[$value])) {
|
42
|
$value = $areas[$value];
|
43
|
}
|
44
|
}
|
45
|
|
46
|
return $value;
|
47
|
}
|
48
|
}
|