You are here

function taxonomy_facets_check_if_node_in_parents in Taxonomy Facets 7.3

1 call to taxonomy_facets_check_if_node_in_parents()
taxonomy_facets_node_submit in ./taxonomy_facets.module

File

./taxonomy_facets.module, line 625

Code

function taxonomy_facets_check_if_node_in_parents($values, $vocabulary_name, $filed_name) {
  $all_tids = array();
  foreach ($values as $v) {
    $all_tids[] = $v['tid'];
  }
  foreach ($values as $value) {
    $parents_tids = array();
    $parents = taxonomy_get_parents_all($value['tid']);
    foreach ($parents as $parent) {
      $parents_tids[] = $parent->tid;
    }
    $difference = array_diff($parents_tids, $all_tids);

    // Check if this tid is also in all parents.
    foreach ($difference as $diff) {
      drupal_set_message('There was a problem in the field ' . $filed_name . '. Your taxonomy term ' . taxonomy_term_load($diff)->name . ' has a parent that you have not selected. Please select all the parent terms or you node may not appear in the result of a taxo faceted filtering.
         For more info see <a href="/admin/config/search/tax_faceted_nav">Taxo faceted module admin form</a>', 'warning');
    }
    if ($difference) {
      break;
    }
  }
}