8000 merged branch willdurand/fix-propel-bridge (PR #3266) · Olajide/symfony@ffef177 · GitHub
[go: up one dir, main page]

Skip to content

Commit ffef177

Browse files
committed
merged branch willdurand/fix-propel-bridge (PR symfony#3266)
Commits ------- 3c227fd [Propel] Fixed naming due to changes in #87b16e7015c02e794c33dbfc05812cf070b4ac68 Discussion ---------- [Propel] Fixed naming due to changes in #87b16e7015c02e794c33dbfc05812cf070b4ac68 + minor CS fix I'll provide unit tests for the Propel bridge in a separate PR.
2 parents 2cd2467 + 3c227fd commit ffef177

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
use Symfony\Component\Form\Util\PropertyPath;
1515
use Symfony\Component\Form\Exception\FormException;
16-
use Symfony\Component\Form\Extension\Core\ChoiceList\ArrayChoiceList;
16+
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
1717

1818
/**
1919
* Widely inspirated by the EntityChoiceList (Symfony2).
2020
*
2121
* @author William Durand <william.durand1@gmail.com>
2222
*/
23-
class ModelChoiceList extends ArrayChoiceList
23+
class ModelChoiceList extends ObjectChoiceList
2424
{
2525
/**
2626
* The models from which the user can choose
@@ -89,61 +89,6 @@ public function __construct($class, $property = null, $choices = array(), $query
8989
parent::__construct($choices);
9090
}
9191

92-
/**
93-
* Initializes the choices and returns them
94-
*
95-
* The choices are generated from the models. If the models have a
96-
* composite identifier, the choices are indexed using ascending integers.
97-
* Otherwise the identifiers are used as indices.
98-
*
99-
* If the models were passed in the "choices" option, this method
100-
* does not have any significant overhead. Otherwise, if a query object
101-
* was passed in the "query" option, this query is now used and executed.
102-
* In the last case, all models for the underlying class are fetched.
103-
*
104-
* If the option "property" was passed, the property path in that option
105-
* is used as option values. Otherwise this method tries to convert
106-
* objects to strings using __toString().
107-
*
108-
* @return array An array of choices
109-
*/
110-
protected function load()
111-
{
112-
parent::load();
113-
114-
if ($this->choices) {
115-
$models = $this->choices;
116-
} else {
117-
$models = $this->query->find();
118-
}
119-
120-
$this->choices = array();
121-
$this->models = array();
122-
123-
foreach ($models as $key => $model) {
124-
if ($this->propertyPath) {
125-
// If the property option was given, use it
126-
$value = $this->propertyPath->getValue($model);
127-
} else {
128-
// Otherwise expect a __toString() method in the model
129-
$value = (string)$model;
130-
}
131-
132-
if (count($this->identifier) > 1) {
133-
// When the identifier consists of multiple field, use
134-
// naturally ordered keys to refer to the choices
135-
$this->choices[$key] = $value;
136-
$this->models[$key] = $model;
137-
} else {
138-
// When the identifier is a single field, index choices by
139-
// model ID for performance reasons
140-
$id = current($this->getIdentifierValues($model));
141-
$this->choices[$id] = $value;
142-
$this->models[$id] = $model;
143-
}
144-
}
145-
}
146-
14792
public function getIdentifier()
14893
{
14994
return $this->identifier;
@@ -226,4 +171,59 @@ public function getIdentifierValues($model)
226171

227172
return $model->getPrimaryKeys();
228173
}
174+
175+
/**
176+
* Initializes the choices and returns them
177+
*
178+
* The choices are generated from the models. If the models have a
179+
* composite identifier, the choices are indexed using ascending integers.
180+
* Otherwise the identifiers are used as indices.
181+
*
182+
* If the models were passed in the "choices" option, this method
183+
* does not have any significant overhead. Otherwise, if a query object
184+
* was passed in the "query" option, this query is now used and executed.
185+
* In the last case, all models for the underlying class are fetched.
186+
*
187+
* If the option "property" was passed, the property path in that option
188+
* is used as option values. Otherwise this method tries to convert
189+
* objects to strings using __toString().
190+
*
191+
* @return array An array of choices
192+
*/
193+
protected function load()
194+
{
195+
parent::load();
196+
197+
if ($this->choices) {
198+
$models = $this->choices;
199+
} else {
200+
$models = $this->query->find();
201+
}
202+
203+
$this->choices = array();
204+
$this->models = array();
205+
206+
foreach ($models as $key => $model) {
207+
if ($this->propertyPath) {
208+
// If the property option was given, use it
209+
$value = $this->propertyPath->getValue($model);
210+
} else {
211+
// Otherwise expect a __toString() method in the model
212+
$value = (string)$model;
213+
}
214+
215+
if (count($this->identifier) > 1) {
216+
// When the identifier consists of multiple field, use
217+
// naturally ordered keys to refer to the choices
218+
$this->choices[$key] = $value;
219+
$this->models[$key] = $model;
220+
} else {
221+
// When the identifier is a single field, index choices by
222+
// model ID for performance reasons
223+
$id = current($this->getIdentifierValues($model));
224+
$this->choices[$id] = $value;
225+
$this->models[$id] = $model;
226+
}
227+
}
228+
}
229229
}

0 commit comments

Comments
 (0)
0