From ffeab06443e86997160382ac7919b4c36db03681 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 14 Aug 2014 10:10:31 +0200 Subject: [PATCH 1/2] Added to form proeperty closure support --- .../Core/ChoiceList/ObjectChoiceList.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php index abf94b514c60b..a495a5edd0bfd 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php @@ -88,7 +88,15 @@ class ObjectChoiceList extends ChoiceList public function __construct($choices, $labelPath = null, array $preferredChoices = array(), $groupPath = null, $valuePath = null, PropertyAccessorInterface $propertyAccessor = null) { $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); - $this->labelPath = null !== $labelPath ? new PropertyPath($labelPath) : null; + if($labelPath !== null){ + if($labelPath instanceof \Closure){ + $this->labelPath = $labelPath; + }else{ + $this->labelPath = new PropertyPath($labelPath); + } + }else{ + $this->labelPath = null; + } $this->groupPath = null !== $groupPath ? new PropertyPath($groupPath) : null; $this->valuePath = null !== $valuePath ? new PropertyPath($valuePath) : null; @@ -248,7 +256,10 @@ private function extractLabels($choices, array &$labels) if (is_array($choice)) { $labels[$i] = array(); $this->extractLabels($choice, $labels[$i]); - } elseif ($this->labelPath) { + } elseif ($this->labelPath instanceof \Closure) { + $clousure = $this->labelPath; + $labels[$i] = $clousure($choice); + }elseif ($this->labelPath) { $labels[$i] = $this->propertyAccessor->getValue($choice, $this->labelPath); } elseif (method_exists($choice, '__toString')) { $labels[$i] = (string) $choice; From dac934aa27a39dc94e950df7006cc7d5cae06bd3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 15 Aug 2014 15:19:03 +0200 Subject: [PATCH 2/2] Added Code Standart --- .../Extension/Core/ChoiceList/ObjectChoiceList.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php index a495a5edd0bfd..cf479efca7e20 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php @@ -88,13 +88,13 @@ class ObjectChoiceList extends ChoiceList public function __construct($choices, $labelPath = null, array $preferredChoices = array(), $groupPath = null, $valuePath = null, PropertyAccessorInterface $propertyAccessor = null) { $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); - if($labelPath !== null){ - if($labelPath instanceof \Closure){ + if ($labelPath !== null) { + if ($labelPath instanceof \Closure) { $this->labelPath = $labelPath; - }else{ + } else { $this->labelPath = new PropertyPath($labelPath); } - }else{ + } else { $this->labelPath = null; } $this->groupPath = null !== $groupPath ? new PropertyPath($groupPath) : null; @@ -259,7 +259,7 @@ private function extractLabels($choices, array &$labels) } elseif ($this->labelPath instanceof \Closure) { $clousure = $this->labelPath; $labels[$i] = $clousure($choice); - }elseif ($this->labelPath) { + } elseif ($this->labelPath) { $labels[$i] = $this->propertyAccessor->getValue($choice, $this->labelPath); } elseif (method_exists($choice, '__toString')) { $labels[$i] = (string) $choice;