/**
  * {@inheritdoc}
  */
 public function getStructuredValues()
 {
     if (!$this->loadedList) {
         $this->loadedList = $this->loader->loadChoiceList($this->value);
     }
     return $this->loadedList->getStructuredValues();
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function getStructuredValues()
 {
     if ($this->loaded) {
         // Check whether the loader has the same cache
         if ($this->loadedList !== $this->loader->loadChoiceList($this->value)) {
             @trigger_error(sprintf('Caching the choice list in %s is deprecated since 3.1 and will not happen in 4.0. Cache the list in the %s instead.', __CLASS__, ChoiceLoaderInterface::class), E_USER_DEPRECATED);
         }
         return $this->loadedList->getStructuredValues();
     }
     // BC
     $this->loadedList = $this->loader->loadChoiceList($this->value);
     $this->loaded = true;
     return $this->loadedList->getStructuredValues();
     // In 4.0 keep the following line only:
     // return $this->loader->loadChoiceList($this->value)->getStructuredValues();
 }
 /**
  * {@inheritdoc}
  */
 public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
 {
     $preferredViews = array();
     $otherViews = array();
     $choices = $list->getChoices();
     $keys = $list->getOriginalKeys();
     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 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 $value => $choice) {
             self::addChoiceViewGroupedBy($groupBy, $choice, (string) $value, $label, $keys, $index, $attr, $preferredChoices, $preferredViews, $otherViews);
         }
     } else {
         // Otherwise use the original structure of the choices
         self::addChoiceViewsGroupedBy($list->getStructuredValues(), $label, $choices, $keys, $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);
 }
 public function testGetStructuredValues()
 {
     $this->assertSame($this->values, $this->list->getStructuredValues());
 }