protected function clearParents(TaxonomyTermInterface $term)
 {
     if ($term->hasParent()) {
         $parent = $term->getParent();
         $this->cacheService->clearByTags(['route_taxonomy/term/get', 'param_term_' . $parent->getId()]);
         $this->clearParents($parent);
     }
 }
 /**
  * @param TaxonomyTermInterface $term
  * @param array                 $array
  */
 protected function retrieveTerms(TaxonomyTermInterface $term, array &$array)
 {
     while ($term->hasParent()) {
         $name = $term->getTaxonomy()->getName();
         $array[$name][] = $term->getName();
         $term = $term->getParent();
     }
 }
示例#3
0
 protected function ajaxify(TaxonomyTermInterface $term)
 {
     $data = ['id' => $term->getId(), 'name' => $term->getName(), 'taxonomy' => $term->getTaxonomy()->getId(), 'url' => $this->url()->fromRoute('uuid/get', ['uuid' => $term->getId()]), 'parent' => $term->hasParent() ? $term->getParent()->getId() : null, 'children' => [], 'items' => []];
     foreach ($term->getChildren() as $child) {
         $data['children'][] = $this->ajaxify($child);
     }
     foreach ($term->getAssociated('entities') as $child) {
         $data['items'][] = ['id' => $child->getId(), 'type' => 'entity'];
     }
     return $data;
 }
 protected function removeMetadata($object, TaxonomyTermInterface $term)
 {
     while ($term->hasParent()) {
         try {
             $metadata = $this->getMetadataManager()->findMetadataByObjectAndKeyAndValue($object, $term->getTaxonomy()->getName(), $term->getName());
             $this->getMetadataManager()->removeMetadata($metadata->getId());
         } catch (MetadataNotFoundException $e) {
         }
         $term = $term->getParent();
     }
 }
 protected function iterBranch(TaxonomyTermInterface $term, $maxDepth)
 {
     $currDepth = 0;
     while ($term->hasParent()) {
         if ($term->isTrashed()) {
             return $maxDepth;
         }
         $term = $term->getParent();
         $currDepth++;
         if ($currDepth >= $maxDepth) {
             return $currDepth;
         }
     }
     return $currDepth;
 }
 protected function process(TaxonomyTermInterface $term)
 {
     if (!$term->hasParent()) {
         return;
     }
     if ($term->getId() === null) {
         $this->getAliasManager()->flush($term);
     }
     $instance = $term->getInstance();
     $normalizer = $this->normalizer->normalize($term);
     $routeName = $normalizer->getRouteName();
     $routeParams = $normalizer->getRouteParams();
     $router = $this->getAliasManager()->getRouter();
     $url = $router->assemble($routeParams, ['name' => $routeName]);
     $this->getAliasManager()->autoAlias('taxonomyTerm', $url, $term, $instance);
     foreach ($term->getChildren() as $child) {
         $this->process($child);
     }
 }