I searched the forum and found New uploaded file on first position in the panel - but flip:true turns around the whole set of images but sorts in alphabetical order.
I want to add images in the order I upload them to the panel. If I upload new images they shall be added to the top list - also in the order I uploaded them:
Uploading images 10 9 8 should end up in a list of 10 9 8
Afterwards adding images 1 2 3 should end up in the complete list of: 1 2 3 10 9 8
I also tried a hook in config.php
'hooks' => [
'file.create:after' => function ($file) {
$page = $file->page();
if (method_exists($page, 'changeFileSortOnUpload')) {
$page->changeFileSortOnUpload($file);
}
}
],
the model for this looks like this album.php:
class AlbumPage extends Page {
public function cover() {
return $this->content()->get('cover')->toFile()
?? $this->images()->template('image')->first()
?? $this->images()->first();
}
public function changeFileSortOnUpload($file) {
// Neue Datei bekommt Sort-Position 1
$file->changeSort(1);
// Alle anderen Dateien nach hinten schieben
$i = 2;
foreach ($this->files()->not($file) as $f) {
$f->changeSort($i);
$i++;
}
}
}
But that did not work either - ending up several images with Sort: 1 and mixed up with alphabetic sorting.
Any idea how I can achive my goal?
Thanks, Bernd.