You are here

function _taxonomy_csv_check_vocabulary_hierarchy in Taxonomy CSV import/export 7.4

Same name and namespace in other branches
  1. 6.5 taxonomy_csv.vocabulary.api.inc \_taxonomy_csv_check_vocabulary_hierarchy()
  2. 6.2 taxonomy_csv.vocabulary.api.inc \_taxonomy_csv_check_vocabulary_hierarchy()
  3. 6.3 taxonomy_csv.vocabulary.api.inc \_taxonomy_csv_check_vocabulary_hierarchy()
  4. 6.4 taxonomy_csv.vocabulary.api.inc \_taxonomy_csv_check_vocabulary_hierarchy()

Check and update hierarchy flag of a given vocabulary.

Drupal hierarchy check function bugs with vocabularies without hierarchy.

Parameters

$vocabulary: The vocabulary object to check and to update.

$changed_term: (Optional) Useless. Kept for compatibility with taxonomy D7 function.

Return value

Updated hierarchy level.

1 call to _taxonomy_csv_check_vocabulary_hierarchy()
_taxonomy_csv_info_vocabulary in import/taxonomy_csv.import.result.inc
Check created vocabularies and return formatted info on them.

File

./taxonomy_csv.vocabulary.api.inc, line 267
Prepare and manage vocabularies.

Code

function _taxonomy_csv_check_vocabulary_hierarchy($vocabulary, $changed_term = '') {
  $tree = taxonomy_get_tree($vocabulary->vid);
  $hierarchy = 0;
  foreach ($tree as $term) {

    // Check this term's parent count.
    if (count($term->parents) > 1) {
      $hierarchy = 2;
      break;
    }
    elseif (count($term->parents) == 1 && 0 != array_shift($term->parents)) {
      $hierarchy = 1;
    }
  }
  if ($hierarchy != $vocabulary->hierarchy) {
    $vocabulary->hierarchy = $hierarchy;
    taxonomy_vocabulary_save($vocabulary);
  }
  return $hierarchy;
}