Projet

Général

Profil

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

root / drupal7 / sites / all / modules / addressfield / views / addressfield_views_handler_field_country.inc @ 651307cd

1
<?php
2

    
3
/**
4
 * Defines a field handler that can display the country name instead of the two
5
 * character country code for an address field country value.
6
 */
7
class addressfield_views_handler_field_country extends views_handler_field {
8

    
9
  function option_definition() {
10
    $options = parent::option_definition();
11
    $options['display_name'] = array('default' => TRUE);
12
    return $options;
13
  }
14

    
15
  function options_form(&$form, &$form_state) {
16
    parent::options_form($form, $form_state);
17

    
18
    $form['display_name'] = array(
19
      '#type' => 'checkbox',
20
      '#title' => t('Display the localized country name instead of the two character country code'),
21
      '#default_value' => $this->options['display_name'],
22
    );
23
  }
24

    
25
  function get_value($values, $field = NULL) {
26
    $value = parent::get_value($values, $field);
27

    
28
    // If we have a value for the field, look for the country name in the
29
    // Address Field options list array if specified.
30
    if (!empty($value) && !empty($this->options['display_name'])) {
31
      $countries = _addressfield_country_options_list();
32

    
33
      if (!empty($countries[$value])) {
34
        $value = $countries[$value];
35
      }
36
    }
37

    
38
    return $value;
39
  }
40
}