/**
  * {@inheritdoc}
  */
 public function buildResponse(AutocompleteResults $results, AutocompleteContextInterface $context)
 {
     $array = [];
     $property = $context->getParameter('autocomplete');
     $accessor = new PropertyAccessor();
     foreach ($results as $id => $result) {
         if ($accessor->isReadable($result, $property)) {
             $array[] = $accessor->getValue($result, $property);
         }
     }
     return new JsonResponse($array);
 }
 /**
  * {@inheritdoc}
  */
 public function buildResponse(AutocompleteResults $results, AutocompleteContextInterface $context)
 {
     $data['results'] = [];
     $templateResult = $context->getParameter('select2_template_result');
     $templateSelection = $context->getParameter('select2_template_selection');
     foreach ($results as $id => $result) {
         $data['results'][] = ['id' => $id, 'text' => $this->renderSelect2Item($id, $result, $templateResult), 'selection_text' => $this->renderSelect2Item($id, $result, $templateSelection)];
     }
     if ($max = $context->getParameter('max_results', false)) {
         $data['pagination'] = ['more' => $results->count() == $max];
     }
     return new JsonResponse($data);
 }
 /**
  * {@inheritdoc}
  */
 public function buildResponse(AutocompleteResults $results, AutocompleteContextInterface $context)
 {
     $accessor = new PropertyAccessor();
     $data['results'] = [];
     $property = $context->getParameter('autocomplete');
     foreach ($results as $id => $result) {
         if ($accessor->isReadable($result, $property)) {
             $value = $accessor->getValue($result, $property);
             $data['results'][] = ['id' => $value, 'text' => $value];
         }
     }
     if ($max = $context->getParameter('max_results', false)) {
         $data['pagination'] = ['more' => $results->count() == $max];
     }
     return new JsonResponse($data);
 }
 /**
  * orderBy.
  *
  * @param QueryBuilder                 $qb
  * @param AutocompleteContextInterface $context
  */
 protected function orderBy(QueryBuilder $qb, AutocompleteContextInterface $context)
 {
     $alias = $qb->getRootAliases()[0];
     $orderBy = $context->getParameter('order_by');
     if (!$orderBy) {
         return;
     }
     if (is_string($orderBy)) {
         $orderBy = [$orderBy];
     }
     foreach ($orderBy as $orderByField => $orderByDir) {
         if (is_int($orderByField)) {
             $orderByField = $orderByDir;
             $orderByDir = null;
         }
         $qb->addOrderBy("{$alias}.{$orderByField}", $orderByDir);
     }
 }