Querys a Taxonomia

mail@pastecode.io avatar
unknown
php
a month ago
580 B
1
Indexable
Never
public function getOptions($vid, $parent, bool $full = false) {
    if($parent === 0) {
      $terms = $this->manager->getStorage('taxonomy_term')->loadTree($vid);
    } else {
      $terms = $this->manager->getStorage('taxonomy_term')->loadTree($vid, $parent, 1, FALSE);
    }
    
    $options = array();
    
    foreach($terms AS $term) {
      if($parent === 0 AND !$full) {
        if(!empty($term->parents[0] === '0')) {
          $options[$term->tid] = $term->name;
        }
      } else {
        $options[$term->tid] = $term->name;
      }
    }
    return $options;
 }
Leave a Comment