コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function getPersistentParameters()
 {
     $parameters = parent::getPersistentParameters();
     if (!$this->hasRequest()) {
         return $parameters;
     }
     $filter = $this->getRequest()->get('filter');
     if ($filter && array_key_exists('context', $this->getRequest()->get('filter'))) {
         $context = $filter['context']['value'];
     } else {
         $context = $this->getRequest()->get('context', $this->pool->getDefaultContext());
     }
     $providers = $this->pool->getProvidersByContext($context);
     $provider = $this->getRequest()->get('provider');
     // if the context has only one provider, set it into the request
     // so the intermediate provider selection is skipped
     if (count($providers) == 1 && null === $provider) {
         $provider = array_shift($providers)->getName();
         $this->getRequest()->query->set('provider', $provider);
     }
     $categoryId = $this->getRequest()->get('category');
     if (!$categoryId) {
         $categoryId = $this->categoryManager->getRootCategory($context)->getId();
     }
     return array_merge($parameters, array('context' => $context, 'category' => $categoryId, 'hide_context' => (bool) $this->getRequest()->get('hide_context')));
 }
コード例 #2
0
 /**
  * @param Options $options
  *
  * @return array
  */
 public function getChoices(Options $options)
 {
     if (!$options['category'] instanceof CategoryInterface) {
         return array();
     }
     if ($options['context'] === null) {
         $categories = $this->manager->getRootCategories();
     } else {
         $categories = array($this->manager->getRootCategory($options['context']));
     }
     $choices = array();
     foreach ($categories as $category) {
         $choices[$category->getId()] = sprintf('%s (%s)', $category->getName(), $category->getContext()->getId());
         $this->childWalker($category, $options, $choices);
     }
     return $choices;
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function execute(BlockContextInterface $blockContext, Response $response = null)
 {
     $category = $this->getCategory($blockContext->getSetting('categoryId'), $blockContext->getSetting('category'));
     $root = $this->categoryManager->getRootCategory($blockContext->getSetting('context'));
     return $this->renderResponse($blockContext->getTemplate(), array('context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'category' => $category, 'root' => $root), $response);
 }