/**
  * @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();
     }
 }
 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);
     }
 }
 protected function getPath(TaxonomyTermInterface $taxonomyTerm, $string = null)
 {
     $name = $taxonomyTerm->getName();
     $parent = $taxonomyTerm->getParent();
     $string = $name . '/' . $string;
     if ($parent && $parent->getTaxonomy()->getName() != 'root') {
         return $this->getPath($parent, $string);
     }
     return $string;
 }
 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 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 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);
     }
 }
 /**
  * @see \Zend\Stdlib\Extractor\ExtractionInterface::extract()
  * @param TaxonomyTermInterface $object
  * @return array
  */
 public function extract($object)
 {
     $term = $object->getTerm();
     return ['id' => is_object($object) ? $object->getId() : null, 'term' => ['id' => is_object($term) ? $term->getId() : null, 'name' => is_object($term) ? $term->getName() : null], 'taxonomy' => is_object($object->getTaxonomy()) ? $object->getTaxonomy()->getId() : null, 'parent' => is_object($object->getParent()) ? $object->getParent()->getId() : null, 'description' => $object->getDescription(), 'position' => $object->getPosition()];
 }
 protected function iterAssociationNodes(Collection $collection, TaxonomyTermInterface $term, $associations, array $allowedTaxonomies)
 {
     foreach ($term->getAssociated($associations) as $link) {
         $collection->add($link);
     }
     foreach ($term->getChildren() as $child) {
         if (empty($allowedTaxonomies) || in_array($child->getTaxonomy()->getName(), $allowedTaxonomies)) {
             $this->iterAssociationNodes($collection, $child, $associations, $allowedTaxonomies);
         }
     }
 }
 protected function getEntities(TaxonomyTermInterface $term)
 {
     return $term->getAssociatedRecursive('entities');
 }
 /**
  * @param TaxonomyInterface|TaxonomyTermInterface|string $nameOrObject
  * @throws Exception\InvalidArgumentException
  * @return \Taxonomy\Options\TaxonomyOptions
  */
 public function getOptions($nameOrObject)
 {
     if ($nameOrObject instanceof TaxonomyInterface) {
         $name = $nameOrObject->getName();
     } elseif ($nameOrObject instanceof TaxonomyTermInterface) {
         $name = $nameOrObject->getTaxonomy()->getName();
     } elseif (is_string($nameOrObject)) {
         $name = $nameOrObject;
     } else {
         throw new Exception\InvalidArgumentException(sprintf('Expected $nameOrObject to be TaxonomyInterface, TaxonomyTermInterface or string but got "%s"', is_object($nameOrObject) ? get_class($nameOrObject) : gettype($nameOrObject)));
     }
     return $this->moduleOptions->getType($name);
 }
 /**
  * @param TaxonomyTermInterface $term
  * @param string                $parent
  * @return string
  */
 protected function processSlugs(TaxonomyTermInterface $term, $parent)
 {
     return $term->getTaxonomy()->getName() != $parent ? $this->processSlugs($term->getParent(), $parent) . $term->getName() . '/' : '';
 }