private function handleChoiceListValues(ChoiceListInterface $choiceList) { $choices = array(); foreach (array($choiceList->getPreferredViews(), $choiceList->getRemainingViews()) as $viewList) { $choices = array_merge($choices, $this->handleChoiceViewsHierarchy($viewList)); } return $choices; }
/** * {@inheritdoc} */ public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null) { // Backwards compatibility if ($list instanceof LegacyChoiceListInterface && empty($preferredChoices) && null === $label && null === $index && null === $groupBy && null === $attr) { $mapToNonLegacyChoiceView = function (LegacyChoiceView $choiceView) { return new ChoiceView($choiceView->label, $choiceView->value, $choiceView->data); }; return new ChoiceListView(array_map($mapToNonLegacyChoiceView, $list->getRemainingViews()), array_map($mapToNonLegacyChoiceView, $list->getPreferredViews())); } $preferredViews = array(); $otherViews = array(); $choices = $list->getChoices(); $values = $list->getValues(); if (!is_callable($preferredChoices) && !empty($preferredChoices)) { $preferredChoices = function ($choice) use($preferredChoices) { return false !== array_search($choice, $preferredChoices, true); }; } // The names are generated from an incrementing integer by default if (null === $index) { $index = 0; } // If $groupBy is not given, no grouping is done if (empty($groupBy)) { foreach ($choices as $key => $choice) { self::addChoiceView($choice, $key, $label, $values, $index, $attr, $preferredChoices, $preferredViews, $otherViews); } return new ChoiceListView($otherViews, $preferredViews); } // If $groupBy is a callable, choices are added to the group with the // name returned by the callable. If the callable returns null, the // choice is not added to any group if (is_callable($groupBy)) { foreach ($choices as $key => $choice) { self::addChoiceViewGroupedBy($groupBy, $choice, $key, $label, $values, $index, $attr, $preferredChoices, $preferredViews, $otherViews); } } else { // If $groupBy is passed as array, use that array as template for // constructing the groups self::addChoiceViewsGroupedBy($groupBy, $label, $choices, $values, $index, $attr, $preferredChoices, $preferredViews, $otherViews); } // Remove any empty group view that may have been created by // addChoiceViewGroupedBy() foreach ($preferredViews as $key => $view) { if ($view instanceof ChoiceGroupView && 0 === count($view->choices)) { unset($preferredViews[$key]); } } foreach ($otherViews as $key => $view) { if ($view instanceof ChoiceGroupView && 0 === count($view->choices)) { unset($otherViews[$key]); } } return new ChoiceListView($otherViews, $preferredViews); }