You are here

function taxonomy_xml_get_literal_string in Taxonomy import/export via XML 7

Same name and namespace in other branches
  1. 5.2 rdf_format.inc \taxonomy_xml_get_literal_string()
  2. 5 rdf_format.inc \taxonomy_xml_get_literal_string()
  3. 6.2 rdf_format.inc \taxonomy_xml_get_literal_string()
  4. 6 rdf_format.inc \taxonomy_xml_get_literal_string()

Choose a string from an array of language-tagged possibilities.

Util func to help read complex RDF statements.

If we want just one string but the RDF has given us a choice, like of different languages, need to pick the right one.

Parameters

array $values:

string $attname: Just for debug

2 calls to taxonomy_xml_get_literal_string()
taxonomy_xml_canonicize_predicates in ./taxonomy_xml.process.inc
Convert aliased predicates into common ones.
taxonomy_xml_merge_predicates_into_attributes in ./taxonomy_xml.process.inc
Merge all predicate data into a simpler array.

File

./taxonomy_xml.module, line 866
Make it possible to import and export taxonomies as XML documents.

Code

function taxonomy_xml_get_literal_string($values, $attname = '') {
  if (!is_array($values)) {
    return trim($values);
  }

  // May need to choose language
  if (count($values) == 1) {
    $out = array_pop($values);
  }
  else {

    // TODO add language selector
    if ($label = @$values['en']) {
      $out = $label;
    }
    else {

      // Fine, whatever. Grab the first.
      watchdog('taxonomy_xml', 'Trying to pick a string from among a list of alternatives %attname = (%list) - this may not be the best choice, but it\'s the best I can do', array(
        '%list' => join(', ', $values),
        '%attname' => $attname,
      ), WATCHDOG_NOTICE);
      $out = reset($values);
    }
  }
  return trim($out);
}