/**
  * {@inheritdoc}
  */
 public function loadChoiceList($value = null)
 {
     if ($this->choiceList) {
         return $this->choiceList;
     }
     return $this->choiceList = $this->factory->createListFromChoices($this->repository->findAll(), $value);
 }
 /**
  * {@inheritdoc}
  */
 public function loadChoiceList($value = null)
 {
     if ($this->choiceList) {
         return $this->choiceList;
     }
     $objects = $this->objectLoader ? $this->objectLoader->getEntities() : $this->manager->getRepository($this->class)->findAll();
     $this->choiceList = $this->factory->createListFromChoices($objects, $value);
     return $this->choiceList;
 }
 /**
  * {@inheritdoc}
  */
 public function loadChoiceList($value = null)
 {
     if ($this->choiceList) {
         return $this->choiceList;
     }
     $models = iterator_to_array($this->query->find());
     $this->choiceList = $this->factory->createListFromChoices($models, $value);
     return $this->choiceList;
 }
 /**
  * {@inheritdoc}
  */
 public function loadChoiceList($value = null)
 {
     if ($this->choiceList) {
         return $this->choiceList;
     }
     $ldapObjects = $this->getLdapObjectsByQuery();
     $choices = [];
     /** @var LdapObject $object */
     foreach ($ldapObjects as $object) {
         $choices[$object->get($this->labelAttribute)] = $object;
     }
     $this->choiceList = $this->factory->createListFromChoices($choices, $this->id);
     return $this->choiceList;
 }
 private function createChoiceListView(ChoiceListInterface $choiceList, array $options)
 {
     // If no explicit grouping information is given, use the structural
     // information from the "choices" option for creating groups
     if (!$options['group_by'] && $options['choices']) {
         $options['group_by'] = !$options['choices_as_values'] ? self::flipRecursive($options['choices']) : $options['choices'];
     }
     return $this->choiceListFactory->createView($choiceList, $options['preferred_choices'], $options['choice_label'], $options['choice_name'], $options['group_by'], $options['choice_attr']);
 }
 /**
  * {@inheritdoc}
  */
 public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
 {
     // The input is not validated on purpose. This way, the decorated
     // factory may decide which input to accept and which not.
     $hash = self::generateHash(array($list, $preferredChoices, $label, $index, $groupBy, $attr));
     if (!isset($this->views[$hash])) {
         $this->views[$hash] = $this->decoratedFactory->createView($list, $preferredChoices, $label, $index, $groupBy, $attr);
     }
     return $this->views[$hash];
 }
 /**
  * {@inheritdoc}
  *
  * @param ChoiceListInterface                     $list             The choice list
  * @param null|array|callable|string|PropertyPath $preferredChoices The preferred choices
  * @param null|callable|string|PropertyPath       $label            The callable or path generating the choice labels
  * @param null|callable|string|PropertyPath       $index            The callable or path generating the view indices
  * @param null|callable|string|PropertyPath       $groupBy          The callable or path generating the group names
  * @param null|array|callable|string|PropertyPath $attr             The callable or path generating the HTML attributes
  *
  * @return ChoiceListView The choice list view
  */
 public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
 {
     $accessor = $this->propertyAccessor;
     if (is_string($label) && !is_callable($label)) {
         $label = new PropertyPath($label);
     }
     if ($label instanceof PropertyPath) {
         $label = function ($choice) use($accessor, $label) {
             return $accessor->getValue($choice, $label);
         };
     }
     if (is_string($preferredChoices) && !is_callable($preferredChoices)) {
         $preferredChoices = new PropertyPath($preferredChoices);
     }
     if ($preferredChoices instanceof PropertyPath) {
         $preferredChoices = function ($choice) use($accessor, $preferredChoices) {
             try {
                 return $accessor->getValue($choice, $preferredChoices);
             } catch (UnexpectedTypeException $e) {
                 // Assume not preferred if not readable
                 return false;
             }
         };
     }
     if (is_string($index) && !is_callable($index)) {
         $index = new PropertyPath($index);
     }
     if ($index instanceof PropertyPath) {
         $index = function ($choice) use($accessor, $index) {
             return $accessor->getValue($choice, $index);
         };
     }
     if (is_string($groupBy) && !is_callable($groupBy)) {
         $groupBy = new PropertyPath($groupBy);
     }
     if ($groupBy instanceof PropertyPath) {
         $groupBy = function ($choice) use($accessor, $groupBy) {
             try {
                 return $accessor->getValue($choice, $groupBy);
             } catch (UnexpectedTypeException $e) {
                 // Don't group if path is not readable
             }
         };
     }
     if (is_string($attr) && !is_callable($attr)) {
         $attr = new PropertyPath($attr);
     }
     if ($attr instanceof PropertyPath) {
         $attr = function ($choice) use($accessor, $attr) {
             return $accessor->getValue($choice, $attr);
         };
     }
     return $this->decoratedFactory->createView($list, $preferredChoices, $label, $index, $groupBy, $attr);
 }
 /**
  * {@inheritdoc}
  */
 public function formatResponseData(AjaxChoiceLoaderInterface $choiceLoader)
 {
     $view = $this->choiceListFactory->createView($choiceLoader->loadPaginatedChoiceList(), null, $choiceLoader->getLabel());
     return array('size' => $choiceLoader->getSize(), 'pageNumber' => $choiceLoader->getPageNumber(), 'pageSize' => $choiceLoader->getPageSize(), 'search' => $choiceLoader->getSearch(), 'items' => FormatterUtil::formatResultData($this, $view));
 }
Exemple #9
0
 private function createChoiceListView(ChoiceListInterface $choiceList, array $options)
 {
     return $this->choiceListFactory->createView($choiceList, $options['preferred_choices'], $options['choice_label'], $options['choice_name'], $options['group_by'], $options['choice_attr']);
 }
 /**
  * {@inheritdoc}
  *
  * @param ChoiceListInterface                     $list             The choice list
  * @param null|array|callable|string|PropertyPath $preferredChoices The preferred choices
  * @param null|callable|string|PropertyPath       $label            The callable or path generating the choice labels
  * @param null|callable|string|PropertyPath       $index            The callable or path generating the view indices
  * @param null|callable|string|PropertyPath       $groupBy          The callable or path generating the group names
  * @param null|array|callable|string|PropertyPath $attr             The callable or path generating the HTML attributes
  *
  * @return ChoiceListView The choice list view
  */
 public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
 {
     $accessor = $this->propertyAccessor;
     if (is_string($label) && !is_callable($label)) {
         $label = new PropertyPath($label);
     } elseif (is_string($label) && is_callable($label)) {
         @trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\\Closure" instead.', E_USER_DEPRECATED);
     }
     if ($label instanceof PropertyPath) {
         $label = function ($choice) use($accessor, $label) {
             return $accessor->getValue($choice, $label);
         };
     }
     if (is_string($preferredChoices) && !is_callable($preferredChoices)) {
         $preferredChoices = new PropertyPath($preferredChoices);
     } elseif (is_string($preferredChoices) && is_callable($preferredChoices)) {
         @trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\\Closure" instead.', E_USER_DEPRECATED);
     }
     if ($preferredChoices instanceof PropertyPath) {
         $preferredChoices = function ($choice) use($accessor, $preferredChoices) {
             try {
                 return $accessor->getValue($choice, $preferredChoices);
             } catch (UnexpectedTypeException $e) {
                 // Assume not preferred if not readable
                 return false;
             }
         };
     }
     if (is_string($index) && !is_callable($index)) {
         $index = new PropertyPath($index);
     } elseif (is_string($index) && is_callable($index)) {
         @trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\\Closure" instead.', E_USER_DEPRECATED);
     }
     if ($index instanceof PropertyPath) {
         $index = function ($choice) use($accessor, $index) {
             return $accessor->getValue($choice, $index);
         };
     }
     if (is_string($groupBy) && !is_callable($groupBy)) {
         $groupBy = new PropertyPath($groupBy);
     } elseif (is_string($groupBy) && is_callable($groupBy)) {
         @trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\\Closure" instead.', E_USER_DEPRECATED);
     }
     if ($groupBy instanceof PropertyPath) {
         $groupBy = function ($choice) use($accessor, $groupBy) {
             try {
                 return $accessor->getValue($choice, $groupBy);
             } catch (UnexpectedTypeException $e) {
                 // Don't group if path is not readable
             }
         };
     }
     if (is_string($attr) && !is_callable($attr)) {
         $attr = new PropertyPath($attr);
     } elseif (is_string($attr) && is_callable($attr)) {
         @trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\\Closure" instead.', E_USER_DEPRECATED);
     }
     if ($attr instanceof PropertyPath) {
         $attr = function ($choice) use($accessor, $attr) {
             return $accessor->getValue($choice, $attr);
         };
     }
     return $this->decoratedFactory->createView($list, $preferredChoices, $label, $index, $groupBy, $attr);
 }