/**
  * {@inheritdoc}
  */
 public function getViewData(DocumentIterator $result, ViewData $data)
 {
     /** @var ChoicesAwareViewData $data */
     $unsortedChoices = [];
     /** @var ValueAggregation $bucket */
     foreach ($this->fetchAggregation($result, $data->getName()) as $bucket) {
         $bucket = $bucket->getValue();
         $active = $this->isChoiceActive($bucket['key'], $data);
         $choice = new ViewData\Choice();
         $choice->setLabel($bucket['key']);
         $choice->setCount($bucket['doc_count']);
         $choice->setActive($active);
         if ($active) {
             $choice->setUrlParameters($this->getUnsetUrlParameters($bucket['key'], $data));
         } else {
             $choice->setUrlParameters($this->getOptionUrlParameters($bucket['key'], $data));
         }
         $unsortedChoices[$bucket['key']] = $choice;
     }
     // Add the prioritized choices first.
     if ($this->getSortType()) {
         $unsortedChoices = $this->addPriorityChoices($unsortedChoices, $data);
     }
     foreach ($unsortedChoices as $choice) {
         $data->addChoice($choice);
     }
     return $data;
 }