/** * {@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 createChoiceList(array $options) { if (null !== $options['choice_loader']) { return $this->choiceListFactory->createListFromLoader($options['choice_loader'], $options['choice_value']); } // Harden against NULL values (like in EntityType and ModelType) $choices = null !== $options['choices'] ? $options['choices'] : array(); return $this->choiceListFactory->createListFromChoices($choices, $options['choice_value']); }
/** * {@inheritdoc} */ public function createListFromChoices($choices, $value = null) { if ($choices instanceof \Traversable) { $choices = iterator_to_array($choices); } // The value is not validated on purpose. The decorated factory may // decide which values to accept and which not. // We ignore the choice groups for caching. If two choice lists are // requested with the same choices, but a different grouping, the same // choice list is returned. self::flatten($choices, $flatChoices); $hash = self::generateHash(array($flatChoices, $value), 'fromChoices'); if (!isset($this->lists[$hash])) { $this->lists[$hash] = $this->decoratedFactory->createListFromChoices($choices, $value); } return $this->lists[$hash]; }
/** * {@inheritdoc} * * @param array|\Traversable $choices The choices * @param null|callable|string|PropertyPath $value The callable or path for * generating the choice values * * @return ChoiceListInterface The choice list */ public function createListFromChoices($choices, $value = null) { if (is_string($value) && !is_callable($value)) { $value = new PropertyPath($value); } if ($value instanceof PropertyPath) { $accessor = $this->propertyAccessor; $value = function ($choice) use($accessor, $value) { // The callable may be invoked with a non-object/array value // when such values are passed to // ChoiceListInterface::getValuesForChoices(). Handle this case // so that the call to getValue() doesn't break. if (is_object($choice) || is_array($choice)) { return $accessor->getValue($choice, $value); } }; } return $this->decoratedFactory->createListFromChoices($choices, $value); }
/** * {@inheritdoc} * * @param array|\Traversable $choices The choices * @param null|callable|string|PropertyPath $value The callable or path for * generating the choice values * * @return ChoiceListInterface The choice list */ public function createListFromChoices($choices, $value = null) { if (is_string($value) && !is_callable($value)) { $value = new PropertyPath($value); } elseif (is_string($value) && is_callable($value)) { @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 ($value instanceof PropertyPath) { $accessor = $this->propertyAccessor; $value = function ($choice) use($accessor, $value) { // The callable may be invoked with a non-object/array value // when such values are passed to // ChoiceListInterface::getValuesForChoices(). Handle this case // so that the call to getValue() doesn't break. if (is_object($choice) || is_array($choice)) { return $accessor->getValue($choice, $value); } }; } return $this->decoratedFactory->createListFromChoices($choices, $value); }