Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

How to save a whole flex collection in order

Started by Anna 2 years ago · 1 replies · 109 views
2 years ago

Hey everbody,

since I can't get my shiny new custom flex collection to sort itself by date, I thought I'd use a workaround and simply reorder the collection programmatically and then save it with the new order whenever an entry is added (so onFlexAfterSave).

The sorting seems to be simple enough:

PHP
public function onFlexAfterSave(Event $event)
{
    $type = $event['type'];
    $object = $event['object'];
    if($type === 'flex') {
        $collection = Grav::instance()->get('flex')->getCollection('termine');
        if ($collection) {
            $collection = $collection->sort(['datum' => 'ASC']);
            $objects = $collection->toArray();
            //var_dump($objects);
            // ????
        }
    }
}

The sorting works nicely like this – I've dumped this onBuildPagesInitialized because apparently dumping doesn't work in Admin?

But I have no idea how to go about saving the whole thing now…

Your help and ideas are much appreciated!

2 years ago

I figured out the ordering so currently I have no need to further go down this path.

(This is not a solution, I just no longer need one, so I'm leaving this as unsolved.)

👍 1

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 47 1 week ago
Plugins · by Xavier, 4 weeks ago
2 56 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1183 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 50 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 74 2 months ago