location_handler_field_location_province.inc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * @file
  4. * Province field handler.
  5. */
  6. class location_handler_field_location_province extends views_handler_field {
  7. function construct() {
  8. parent::construct();
  9. $this->additional_fields = array(
  10. 'country' => 'country',
  11. );
  12. }
  13. function option_definition() {
  14. $options = parent::option_definition();
  15. $options['style'] = array('default' => 'name');
  16. return $options;
  17. }
  18. function options_form(&$form, &$form_state) {
  19. parent::options_form($form, $form_state);
  20. $form['style'] = array(
  21. '#title' => t('Display style'),
  22. '#type' => 'select',
  23. '#options' => array('name' => t('Province name'), 'code' => t('Province code')),
  24. '#default_value' => $this->options['style'],
  25. );
  26. }
  27. function render($values) {
  28. if ($this->options['style'] == 'name') {
  29. return check_plain(location_province_name($values->{$this->aliases['country']}, $values->{$this->field_alias}));
  30. }
  31. else {
  32. return check_plain(strtoupper($values->{$this->field_alias}));
  33. }
  34. }
  35. }