Пример #1
0
 /**
  * Returns the values corresponding to the given model objects.
  *
  * @param array $models
  *
  * @return array
  *
  * @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
  */
 public function getValuesForChoices(array $models)
 {
     if (!$this->loaded) {
         // Optimize performance for single-field identifiers. We already
         // know that the IDs are used as values
         // Attention: This optimization does not check choices for existence
         if (1 === count($this->identifier)) {
             $values = array();
             foreach ($models as $model) {
                 if ($model instanceof $this->class) {
                     // Make sure to convert to the right format
                     $values[] = $this->fixValue(current($this->getIdentifierValues($model)));
                 }
             }
             return $values;
         }
         $this->load();
     }
     return parent::getValuesForChoices($models);
 }
Пример #2
0
 /**
  * Returns the values corresponding to the given entities.
  *
  * @param array $entities
  *
  * @return array
  *
  * @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
  */
 public function getValuesForChoices(array $entities)
 {
     // Performance optimization
     if (empty($entities)) {
         return array();
     }
     if (!$this->loaded) {
         // Optimize performance for single-field identifiers. We already
         // know that the IDs are used as values
         // Attention: This optimization does not check choices for existence
         if ($this->idAsValue) {
             $values = array();
             foreach ($entities as $i => $entity) {
                 if ($entity instanceof $this->class) {
                     // Make sure to convert to the right format
                     $values[$i] = $this->fixValue(current($this->getIdentifierValues($entity)));
                 }
             }
             return $values;
         }
         $this->load();
     }
     return parent::getValuesForChoices($entities);
 }