-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Component][Form][ChoiceType] : Add new option to sort group_by value #22136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,8 +90,9 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul | |
* group names | ||
* @param null|array|callable $attr The callable generating the | ||
* HTML attributes | ||
* @param null|array|callable $groupByOrder The group by order | ||
* | ||
* @return ChoiceListView The choice list view | ||
*/ | ||
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null); | ||
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null, $groupByOrder = null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding arguments in an interface is forbidden by our BC policy |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null) | ||
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null, $groupByOrder = null) | ||
{ | ||
$preferredViews = array(); | ||
$otherViews = array(); | ||
|
@@ -81,6 +81,12 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |
$otherViews | ||
); | ||
} | ||
|
||
if ($groupByOrder && is_array($groupByOrder)) { | ||
uksort($otherViews, function ($key1, $key2) use ($groupByOrder) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this logic does not seem to support callable values for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to see this support both callables and predefined arrays. Something like this should work: if ($groupByOrder) {
if (is_callable($groupByOrder)) {
// TODO
} elseif (is_array($groupByOrder)) {
// TODO
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @colinodell , thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The callable should be compatible with
I could then use any type of callable for the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @colinodell thanks, will do that soon |
||
return array_search($key1, $groupByOrder) > array_search($key2, $groupByOrder); | ||
}); | ||
} | ||
} else { | ||
// Otherwise use the original structure of the choices | ||
self::addChoiceViewsGroupedBy( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,10 +148,11 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul | |
* @param null|callable|string|PropertyPath $index The callable or path generating the view indices | ||
* @param null|callable|string|PropertyPath $groupBy The callable or path generating the group names | ||
* @param null|array|callable|string|PropertyPath $attr The callable or path generating the HTML attributes | ||
* @param null|array|callable|string|PropertyPath $groupByOrder The groupBy order | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this does not support a PropertyPath, as you don't handle it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does |
||
* | ||
* @return ChoiceListView The choice list view | ||
*/ | ||
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null) | ||
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null, $groupByOrder = null) | ||
{ | ||
$accessor = $this->propertyAccessor; | ||
|
||
|
@@ -224,6 +225,6 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |
}; | ||
} | ||
|
||
return $this->decoratedFactory->createView($list, $preferredChoices, $label, $index, $groupBy, $attr); | ||
return $this->decoratedFactory->createView($list, $preferredChoices, $label, $index, $groupBy, $attr, $groupByOrder); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,6 +332,7 @@ public function configureOptions(OptionsResolver $resolver) | |
'choice_attr' => null, | ||
'preferred_choices' => array(), | ||
'group_by' => null, | ||
'group_by_order' => null, | ||
'empty_data' => $emptyData, | ||
'placeholder' => $placeholderDefault, | ||
'error_bubbling' => false, | ||
|
@@ -356,6 +357,7 @@ public function configureOptions(OptionsResolver $resolver) | |
$resolver->setAllowedTypes('choice_attr', array('null', 'array', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath')); | ||
$resolver->setAllowedTypes('preferred_choices', array('array', '\Traversable', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath')); | ||
$resolver->setAllowedTypes('group_by', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath')); | ||
$resolver->setAllowedTypes('group_by_order', array('null', 'array', '\Traversable')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this does not match the types supported by the implementation. |
||
} | ||
|
||
/** | ||
|
@@ -444,7 +446,8 @@ private function createChoiceListView(ChoiceListInterface $choiceList, array $op | |
$options['choice_label'], | ||
$options['choice_name'], | ||
$options['group_by'], | ||
$options['choice_attr'] | ||
$options['choice_attr'], | ||
$options['group_by_order'] | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new value must be taken into account when building the cache key, otherwise a list could be reused while it was having a different order