getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.31k stars 168 forks source link

Images with no 'sort' field are being displayed in a different order than shown in the panel #2690

Closed cgundermann closed 4 years ago

cgundermann commented 4 years ago

Good morning!

Describe the bug
Images with no 'sort' field are being displayed in a different order than shown in the panel.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the panel of the starterkit
  2. Open an album in photography (i.e. trees)
  3. Preview the page (click open button)
  4. Compare the order of the images shown in the panel with the ones on the frontend
  5. Go back to the panel, click on the sort button but don't drag around.
  6. Images now have a sort field and be sorted in the same order on the frontend as in the panel

Expected behavior
Right after the upload process, images on the frontend should automatically be sorted in the same order as shown in the panel.

Kirby Version
3.3.6 (but noticed this in older versions as well)

Additional context
Right now I'm solving it like so, but in my opinion it would be nice to have it as a default behavior:

$images = $page->images();
$sortBy = $images->first()->sort()->isNotEmpty() ? 'sort' : 'filename';

foreach($images->sortBy($sortBy, 'asc') as $image):
...

Thanks! 🙂

PS: Haven't tested this with other file types (docs, videos etc.) yet.

distantnative commented 4 years ago

Might this be the same issue as https://github.com/getkirby/kirby/issues/2342?

cgundermann commented 4 years ago

@distantnative I've tested Your suggestion as mentioned here and replaced

// kirby/config/sections/files.php 

elseif ($this->sortable === true) {
  $files = $files->sortBy('sort', 'asc', 'filename', 'asc');
}

with

// kirby/config/sections/files.php

else {
  $files = $files->sortBy('sort', 'asc', 'filename', 'asc');
}

which seems to work fine. If You remove the the sortBy method in the album controller of the starterkit, everything works as expected.

Edit: If You leave the sortBy method in the album controller, then the files are sorted in a weird order again.

distantnative commented 4 years ago

@CrisGraphics Sorry, I totally missed your comment - only stumbled across it today again.

So I think it is https://github.com/getkirby/kirby/pull/2878 but what you describe is probably just related to the controller. If the files should be shown as in the Panel, we need to apply the same sorting (adding filename):

$gallery = $page->images()->sortBy('sort', 'filename');
bastianallgeier commented 4 years ago

cgundermann commented 4 years ago

Thanks for having a look into it again @distantnative! I'm happy, that this will be solved in 3.5. You guys are awesome! 🥳