summaryrefslogtreecommitdiffstats
path: root/includes/i18nviews_handler_field_taxonomy_term_name.inc
blob: 4a923a2a935e9bcd1f1818f0d7892c4d543ce3fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php

/**
 * Field handler to provide simple renderer that allows linking to a taxonomy
 * term.
 */
class i18nviews_handler_field_taxonomy_term_name extends views_handler_field_taxonomy {

  /**
   * Get the value that's supposed to be rendered.
   *
   * @param $values
   *   An object containing all retrieved values.
   * @param $field
   *   Optional name of the field where the value is stored.
   */
  function get_value($values, $field = NULL) {
    $alias = isset($field) ? $this->aliases[$field] : $this->field_alias;
    $alias_localized = $alias . '_i18n';
    if (isset($values->{$alias_localized})) {
      return $values->{$alias_localized};
    }
    return parent::get_value($values, $field);
  }

  /**
   * Translate the taxonomy term name.
   *
   * @param $values
   */
  function pre_render(&$values) {
    foreach ($values as $key => $value) {
      if (isset($value->{$this->field_alias})) {
        $term = new stdClass();
        $term->tid = $this->get_value($value, 'tid');
        $term->vid = $this->get_value($value, 'vid');
        $term->name = $this->get_value($value);
        $values[$key]->{$this->field_alias . '_i18n'} = i18n_taxonomy_term_name($term);
      }
    }
  }
}