/** * List children of a category. * The parent category is provided via its id ('id' request parameter). * The node category to select is given by 'select_node_id' request parameter. * * If the node to select is not a direct child of the parent category, the tree * is expanded until the selected node is found amongs the children * * @param Request $request * * @throws AccessDeniedException * * @Template * * @return array */ public function childrenAction(Request $request) { if (false === $this->securityFacade->isGranted($this->buildAclName('category_list'))) { throw new AccessDeniedException(); } try { $parent = $this->findCategory($request->get('id')); } catch (NotFoundHttpException $e) { return ['categories' => []]; } $selectNodeId = $request->get('select_node_id', -1); try { $selectNode = $this->findCategory($selectNodeId); if (!$this->categoryRepository->isAncestor($parent, $selectNode)) { $selectNode = null; } } catch (NotFoundHttpException $e) { $selectNode = null; } $categories = $this->getChildrenCategories($request, $selectNode); if (null === $selectNode) { $view = 'PimEnrichBundle:CategoryTree:children.json.twig'; } else { $view = 'PimEnrichBundle:CategoryTree:children-tree.json.twig'; } $withItemsCount = (bool) $request->get('with_items_count', false); $includeParent = (bool) $request->get('include_parent', false); $includeSub = (bool) $request->get('include_sub', false); return $this->render($view, ['categories' => $categories, 'parent' => $includeParent ? $parent : null, 'include_sub' => $includeSub, 'item_count' => $withItemsCount, 'select_node' => $selectNode, 'related_entity' => $this->rawConfiguration['related_entity']], new JsonResponse()); }