Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffeab06

Browse files
DanielDaniel
Daniel
authored and
Daniel
committed
Added to form proeperty closure support
1 parent 136c5cb commit ffeab06

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,15 @@ class ObjectChoiceList extends ChoiceList
8888
public function __construct($choices, $labelPath = null, array $preferredChoices = array(), $groupPath = null, $valuePath = null, PropertyAccessorInterface $propertyAccessor = null)
8989
{
9090
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
91-
$this->labelPath = null !== $labelPath ? new PropertyPath($labelPath) : null;
91+
if($labelPath !== null){
92+
if($labelPath instanceof \Closure){
93+
$this->labelPath = $labelPath;
94+
}else{
95+
$this->labelPath = new PropertyPath($labelPath);
96+
}
97+
}else{
98+
$this->labelPath = null;
99+
}
92100
$this->groupPath = null !== $groupPath ? new PropertyPath($groupPath) : null;
93101
$this->valuePath = null !== $valuePath ? new PropertyPath($valuePath) : null;
94102

@@ -248,7 +256,10 @@ private function extractLabels($choices, array &$labels)
248256
if (is_array($choice)) {
249257
$labels[$i] = array();
250258
$this->extractLabels($choice, $labels[$i]);
251-
} elseif ($this->labelPath) {
259+
} elseif ($this->labelPath instanceof \Closure) {
260+
$clousure = $this->labelPath;
261+
$labels[$i] = $clousure($choice);
262+
}elseif ($this->labelPath) {
252263
$labels[$i] = $this->propertyAccessor->getValue($choice, $this->labelPath);
253264
} elseif (method_exists($choice, '__toString')) {
254265
$labels[$i] = (string) $choice;

0 commit comments

Comments
 (0)