/**
  * List children categories
  *
  * @param Request $request    The request object
  * @param int     $identifier The parent category identifier
  *
  * @return array
  */
 public function listSelectedChildrenAction(Request $request, $identifier)
 {
     $parent = $this->repository->findOneByIdentifier($identifier);
     if (null === $parent) {
         return new JsonResponse(null, 404);
     }
     $selectedCategories = $this->repository->getCategoriesByCodes($request->get('selected', []));
     if (0 !== $selectedCategories->count()) {
         $tree = $this->twigExtension->listCategoriesResponse($this->repository->getFilledTree($parent, $selectedCategories), $selectedCategories);
     } else {
         $tree = $this->twigExtension->listCategoriesResponse($this->repository->getFilledTree($parent, new ArrayCollection([$parent])), new ArrayCollection());
     }
     // Returns only children of the given category without the node itself
     if (!empty($tree)) {
         $tree = $tree[0]['children'];
     }
     return new JsonResponse($tree);
 }
 /**
  * Fetch the filled tree
  *
  * @param CategoryInterface $parent
  * @param Collection        $categories
  *
  * @return CategoryInterface[]
  */
 protected function getFilledTree(CategoryInterface $parent, Collection $categories)
 {
     return $this->categoryRepository->getFilledTree($parent, $categories);
 }