/**
  * Returns filter manager.
  *
  * @return FiltersManager
  */
 protected function getFilterManager()
 {
     $container = new FiltersContainer();
     $filter = new MultiTermChoice();
     $filter->setRequestField('choice');
     $filter->setTags(['badged']);
     $filter->setField('color');
     $container->set('choice', $filter);
     return new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product'));
 }
 /**
  * Tests getViewData method.
  *
  * @param DocumentIterator $documentIterator      Document.
  * @param FilterState      $filterState           Filter state of ViewData object..
  * @param array            $viewDataUrlParameters URL parameters of ViewData object.
  *
  * @dataProvider getTestGetViewDataData
  */
 public function testGetViewData($documentIterator, $filterState, $viewDataUrlParameters)
 {
     $mtc = new MultiTermChoice();
     $mtc->setRequestField('choice');
     $mtc->setSortType(['type' => '', 'order' => '', 'priorities' => ['country']]);
     $viewData = $mtc->createViewData();
     $viewData->setName('testName');
     $viewData->setState($filterState);
     $viewData->setUrlParameters($viewDataUrlParameters);
     $mtc->getViewData($documentIterator, $viewData);
 }
 /**
  * {@inheritdoc}
  */
 public function getViewData(DocumentIterator $result, ViewData $data)
 {
     $data = parent::getViewData($result, $data);
     $requestField = $this->getRequestField();
     $choices = $data->getChoices();
     $list = [];
     $active = true;
     foreach ($choices as $choice) {
         $parameters = $choice->getUrlParameters();
         if (isset($parameters[$requestField])) {
             $list = array_merge($list, $parameters[$requestField]);
         }
         $active &= $choice->isActive();
     }
     if (!$active) {
         $this->addSelectAll($data, array_unique($list));
     }
     return $data;
 }