/**
  * List category trees. The select_node_id request parameter
  * allow to send back the tree where the node belongs with a selected
  * attribute
  *
  * @param Request $request
  *
  * @return array
  *
  * @Template
  * @AclAncestor("pim_enrich_category_list")
  */
 public function listTreeAction(Request $request)
 {
     $selectNodeId = $request->get('select_node_id', -1);
     try {
         $selectNode = $this->findCategory($selectNodeId);
     } catch (NotFoundHttpException $e) {
         $selectNode = $this->userContext->getUserTree();
     }
     return array('trees' => $this->categoryManager->getTrees(), 'selectedTreeId' => $selectNode->isRoot() ? $selectNode->getId() : $selectNode->getRoot(), 'include_sub' => (bool) $this->getRequest()->get('include_sub', false), 'product_count' => (bool) $this->getRequest()->get('with_products_count', true), 'related_entity' => $this->getRequest()->get('related_entity', 'product'));
 }
 /**
  * Get all sources
  * @param CategoryInterface $category
  *
  * @return array
  */
 public function getAllSources(CategoryInterface $category = null)
 {
     $sources = [];
     if ($this->isValid()) {
         $categories = $category === null ? $this->categoryManager->getTrees() : $category->getChildren();
         foreach ($categories as $category) {
             $sources[] = ['id' => $category->getCode(), 'text' => sprintf('%s (%s)', $category->getLabel(), $category->getCode())];
             $sources = array_merge($sources, $this->getAllSources($category));
         }
     }
     return $sources;
 }
 function let(SecurityContextInterface $securityContext, LocaleManager $localeManager, ChannelManager $channelManager, CategoryManager $categoryManager, TokenInterface $token, User $user, LocaleInterface $en, LocaleInterface $fr, LocaleInterface $de, ChannelInterface $ecommerce, ChannelInterface $mobile, CategoryInterface $firstTree, CategoryInterface $secondTree)
 {
     $securityContext->getToken()->willReturn($token);
     $token->getUser()->willReturn($user);
     $en->getCode()->willReturn('en_US');
     $fr->getCode()->willReturn('fr_FR');
     $de->getCode()->willReturn('de_DE');
     $en->isActivated()->willReturn(true);
     $fr->isActivated()->willReturn(true);
     $de->isActivated()->willReturn(true);
     $localeManager->getLocaleByCode('en_US')->willReturn($en);
     $localeManager->getLocaleByCode('fr_FR')->willReturn($fr);
     $localeManager->getLocaleByCode('de_DE')->willReturn($de);
     $localeManager->getActiveLocales()->willReturn([$en, $fr, $de]);
     $channelManager->getChannels()->willReturn([$mobile, $ecommerce]);
     $categoryManager->getTrees()->willReturn([$firstTree, $secondTree]);
     $this->beConstructedWith($securityContext, $localeManager, $channelManager, $categoryManager, 'en_US');
 }
 /**
  * Get user category tree
  *
  * @return CategoryInterface
  */
 public function getUserTree()
 {
     $defaultTree = $this->getUserOption('defaultTree');
     return $defaultTree ?: current($this->categoryManager->getTrees());
 }