Skip to content

[Form] ChoiceType "order_group_by" Option #21717

@JProffitt71

Description

@JProffitt71
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 3.2

Right now groups are ordered by their first occurrence in the group_by callable. I've run into a use-case where I cannot guarantee the order of that first occurrence, and need to be able to sort the groups after they are defined. It would be nice if there was an additional option to define a comparator for sorting groups.

In my specific case, I have a group_by function that looks like this:

'group_by' => function ($entity) use ($soonThreshold) {
    switch (true) {
        case $entity->isComplete():
            return 'Complete';
        case $entity->willBeComplete():
            return 'Will Be Complete';
        case $entity->isOverDue():
            return 'Not Complete - Overdue';
        case $entity->isDueBy($soonThreshold):
            return 'Not Complete - Due Soon';
        default:
            return 'Not Complete - Due Later';
    }
}

My application requires these groups to be presented in this order, but I have no way to guarantee that the entities will be ordered in a way that produces that order (even with a query builder).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions