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)); }
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); }