From c1be8433779203d0b6c33cc1fdef11063ce24927 Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 18 Mar 2022 14:14:59 -0300 Subject: [PATCH 1/3] tree categories added --- src/Form/Builder/QueryFilterFormBuilder.php | 23 +++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Form/Builder/QueryFilterFormBuilder.php b/src/Form/Builder/QueryFilterFormBuilder.php index 5c8a36a..a9967d7 100644 --- a/src/Form/Builder/QueryFilterFormBuilder.php +++ b/src/Form/Builder/QueryFilterFormBuilder.php @@ -180,7 +180,7 @@ protected function buildChannelsChoices(): array protected function buildCategoriesChoices(): array { $choices = []; - $categories = $this->taxonRepository->findChildren('category'); + $categories = $this->taxonRepository->findAll(); /** @var TaxonInterface $category */ foreach ($categories as $category) { @@ -192,13 +192,24 @@ protected function buildCategoriesChoices(): array protected function addCategoryToChoices(array $choices, TaxonInterface $category): array { - $choices[$category->getName()] = $category->getId(); + $name = $category->getName() ?? ''; - /** @var TaxonInterface $subcategory */ - foreach ($category->getChildren() as $subcategory) { - $choices = $this->addCategoryToChoices($choices, $subcategory); - } + $name = $this->createTaxonName($category, $name); + + $choices[$name] = $category->getId(); return $choices; } + + private function createTaxonName(TaxonInterface $category, string $name): string + { + if (null !== $category->getParent()) { + /** @var TaxonInterface $parentCategory */ + $parentCategory = $category->getParent(); + $parentName = $parentCategory->getName() ?? ''; + $name = $parentName . '/' . $name; + $name = $this->createTaxonName($parentCategory, $name); + } + return $name; + } } From d94ecc8032919d040a3e037dd91d37e2a029676d Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 25 Mar 2022 12:11:18 -0300 Subject: [PATCH 2/3] fix line feed --- src/Form/Builder/QueryFilterFormBuilder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Form/Builder/QueryFilterFormBuilder.php b/src/Form/Builder/QueryFilterFormBuilder.php index a9967d7..043d775 100644 --- a/src/Form/Builder/QueryFilterFormBuilder.php +++ b/src/Form/Builder/QueryFilterFormBuilder.php @@ -210,6 +210,7 @@ private function createTaxonName(TaxonInterface $category, string $name): string $name = $parentName . '/' . $name; $name = $this->createTaxonName($parentCategory, $name); } + return $name; } } From be262f9bc77eb90bfef39bc5a12fab1eb28b6c44 Mon Sep 17 00:00:00 2001 From: bigboss Date: Fri, 25 Mar 2022 13:03:15 -0300 Subject: [PATCH 3/3] fix tests --- src/Form/Builder/QueryFilterFormBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Form/Builder/QueryFilterFormBuilder.php b/src/Form/Builder/QueryFilterFormBuilder.php index 043d775..c3e063f 100644 --- a/src/Form/Builder/QueryFilterFormBuilder.php +++ b/src/Form/Builder/QueryFilterFormBuilder.php @@ -210,7 +210,7 @@ private function createTaxonName(TaxonInterface $category, string $name): string $name = $parentName . '/' . $name; $name = $this->createTaxonName($parentCategory, $name); } - + return $name; } }