Skip to content

Commit 0fe7097

Browse files
committed
Fixed choice_label_attr option BC layer
1 parent 23df93d commit 0fe7097

File tree

5 files changed

+22
-144
lines changed

5 files changed

+22
-144
lines changed

src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @author Bernhard Schussek <bschussek@gmail.com>
2222
*/
23-
class CachingFactoryDecorator implements ExpandedChoiceListFactoryInterface
23+
class CachingFactoryDecorator implements ChoiceListFactoryInterface
2424
{
2525
/**
2626
* @var ChoiceListFactoryInterface
@@ -152,43 +152,22 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul
152152
/**
153153
* {@inheritdoc}
154154
*/
155-
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
156-
{
157-
return $this->createExpandedView($list, $preferredChoices, $label, $index, $groupBy, $attr);
158-
}
159-
160-
/**
161-
* {@inheritdoc}
162-
*/
163-
public function createExpandedView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null, $labelAttr = null)
155+
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null, $labelAttr = null)
164156
{
165157
// The input is not validated on purpose. This way, the decorated
166158
// factory may decide which input to accept and which not.
167159
$hash = self::generateHash(array($list, $preferredChoices, $label, $index, $groupBy, $attr));
168160

169161
if (!isset($this->views[$hash])) {
170-
// BC layer
171-
if ($this->decoratedFactory instanceof ExpandedChoiceListFactoryInterface) {
172-
$choiceView = $this->decoratedFactory->createExpandedView(
173-
$list,
174-
$preferredChoices,
175-
$label,
176-
$index,
177-
$groupBy,
178-
$attr,
179-
$labelAttr
180-
);
181-
} else {
182-
$choiceView = $this->decoratedFactory->createView(
183-
$list,
184-
$preferredChoices,
185-
$label,
186-
$index,
187-
$groupBy,
188-
$attr
189-
);
190-
}
191-
$this->views[$hash] = $choiceView;
162+
$this->views[$hash] = $this->decoratedFactory->createView(
163+
$list,
164+
$preferredChoices,
165+
$label,
166+
$index,
167+
$groupBy,
168+
$attr,
169+
$labelAttr
170+
);
192171
}
193172

194173
return $this->views[$hash];

src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* @author Bernhard Schussek <bschussek@gmail.com>
2626
*/
27-
class DefaultChoiceListFactory implements ExpandedChoiceListFactoryInterface
27+
class DefaultChoiceListFactory implements ChoiceListFactoryInterface
2828
{
2929
/**
3030
* {@inheritdoc}
@@ -45,15 +45,7 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul
4545
/**
4646
* {@inheritdoc}
4747
*/
48-
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
49-
{
50-
return $this->createExpandedView($list, $preferredChoices, $label, $index, $groupBy, $attr);
51-
}
52-
53-
/**
54-
* {@inheritdoc}
55-
*/
56-
public function createExpandedView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null, $labelAttr = null)
48+
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null, $labelAttr = null)
5749
{
5850
$preferredViews = array();
5951
$otherViews = array();

src/Symfony/Component/Form/ChoiceList/Factory/ExpandedChoiceListFactoryInterface.php

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*
4040
* @author Bernhard Schussek <bschussek@gmail.com>
4141
*/
42-
class PropertyAccessDecorator implements ExpandedChoiceListFactoryInterface
42+
class PropertyAccessDecorator implements ChoiceListFactoryInterface
4343
{
4444
/**
4545
* @var ChoiceListFactoryInterface
@@ -139,11 +139,6 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul
139139
return $this->decoratedFactory->createListFromLoader($loader, $value);
140140
}
141141

142-
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
143-
{
144-
return $this->createExpandedView($list, $preferredChoices, $label, $index, $groupBy, $attr);
145-
}
146-
147142
/**
148143
* {@inheritdoc}
149144
*
@@ -157,7 +152,7 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
157152
*
158153
* @return ChoiceListView The choice list view
159154
*/
160-
public function createExpandedView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null, $labelAttr = null)
155+
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null, $labelAttr = null)
161156
{
162157
$accessor = $this->propertyAccessor;
163158

@@ -231,13 +226,6 @@ public function createExpandedView(ChoiceListInterface $list, $preferredChoices
231226
};
232227
}
233228

234-
// BC Layer
235-
if ($this->decoratedFactory instanceof ExpandedChoiceListFactoryInterface) {
236-
$choiceView = $this->decoratedFactory->createExpandedView($list, $preferredChoices, $label, $index, $groupBy, $attr, $labelAttr);
237-
} else {
238-
$choiceView = $this->decoratedFactory->createView($list, $preferredChoices, $label, $index, $groupBy, $attr);
239-
}
240-
241-
return $choiceView;
229+
return $this->decoratedFactory->createView($list, $preferredChoices, $label, $index, $groupBy, $attr, $labelAttr);
242230
}
243231
}

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,16 +452,10 @@ private function createChoiceList(array $options)
452452

453453
private function createChoiceListView(ChoiceListInterface $choiceList, array $options)
454454
{
455-
if ($this->choiceListFactory instanceof ExpandedChoiceListFactoryInterface) {
456-
return $this->choiceListFactory->createExpandedView(
457-
$choiceList,
458-
$options['preferred_choices'],
459-
$options['choice_label'],
460-
$options['choice_name'],
461-
$options['group_by'],
462-
$options['choice_attr'],
463-
$options['choice_label_attr']
464-
);
455+
// BC
456+
$refMethod = new \ReflectionMethod($this->choiceListFactory, 'createView');
457+
if (6 > $refMethod->getNumberOfParameters()) {
458+
@trigger_error(sprintf('Not passing a "$labelAttr" as sixth argument of "%s" is deprecated since version 3.3 and will trigger an error in 4.0.', $refMethod->getNamespaceName()));
465459
}
466460

467461
return $this->choiceListFactory->createView(
@@ -470,7 +464,8 @@ private function createChoiceListView(ChoiceListInterface $choiceList, array $op
470464
$options['choice_label'],
471465
$options['choice_name'],
472466
$options['group_by'],
473-
$options['choice_attr']
467+
$options['choice_attr'],
468+
$options['choice_label_attr']
474469
);
475470
}
476471
}

0 commit comments

Comments
 (0)