addressfield_views_handler_field_country.inc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Defines a field handler that can display the country name instead of the two
  4. * character country code for an address field country value.
  5. */
  6. class addressfield_views_handler_field_country extends views_handler_field {
  7. function option_definition() {
  8. $options = parent::option_definition();
  9. $options['display_name'] = array('default' => TRUE);
  10. return $options;
  11. }
  12. function options_form(&$form, &$form_state) {
  13. parent::options_form($form, $form_state);
  14. $form['display_name'] = array(
  15. '#type' => 'checkbox',
  16. '#title' => t('Display the localized country name instead of the two character country code'),
  17. '#default_value' => $this->options['display_name'],
  18. );
  19. }
  20. function get_value($values, $field = NULL) {
  21. $value = parent::get_value($values, $field);
  22. // If we have a value for the field, look for the country name in the
  23. // Address Field options list array if specified.
  24. if (!empty($value) && !empty($this->options['display_name'])) {
  25. $countries = _addressfield_country_options_list();
  26. if (!empty($countries[$value])) {
  27. $value = $countries[$value];
  28. }
  29. }
  30. return $value;
  31. }
  32. }