You are here

function taxonomy_csv_term_set_field_values in Taxonomy CSV import/export 7.4

Direct set values of a field of a given term id or object.

@todo To be removed by using of field api.

Values can be names or ids depending on field type (text or term reference).

Parameters

$term_tid: Term object or term id on which to set values. Use of object is quicker.

$field_name: Field to get.

$langcode: (Optional) Language code to use.

Return value

Result array of items.

1 call to taxonomy_csv_term_set_field_values()
_taxonomy_csv_term_format_regular in ./taxonomy_csv.term.api.inc
Format an internal term to a regular term (synonyms and relations).

File

./taxonomy_csv.term.api.inc, line 282
Find, get and set full or detail term items.

Code

function taxonomy_csv_term_set_field_values($term_tid, $field_name, $langcode = 'und') {
  $items = array();
  $term = is_object($term_tid) ? $term_tid : taxonomy_term_load($term_tid);
  $value = $field_name == 'relations' ? 'tid' : 'value';
  if (isset($term->{$field_name})) {
    foreach ($term->{$field_name} as $delta) {
      $items[$langcode][] = array(
        $value => $delta,
      );
    }
  }
  return $items;
}