Disable manual files sorting for non-default languages

Hi,

I’m setting up a multi-language site and I noticed that for the files sections the manual sorting is not consistant across all languages, meaning I can do a files order in one language and a different one in an other language.

I’d prefer if there was only one files order.
Either by disabling sorting entirely for the non-default languages, or by reflecting the sort done in one language in the other ones.

Is there a way to achieve either one of those options?

Thanks!

You can only switch off manual sorting in general, not per language, although this would definitely make sense.

To work around this, you could use a file.changeSort:after hook to update all other languages with the new values.

An alternative could be a custom files section.

Thanks!
I don’t want to bother writing any custom code, so I’ll just tell my client to be careful and only re-order files in the default language.

But that would indeed be a nice feature, to be able to simply add translate: false to a files section

What you can do to ensure that the order is always the same in both languages on the frontend, you could sort by the sort field in the default language. So even if the sort order is messed up in the Panel, you would still end up with the correct sort order on the frontend.

I use this hook to sync sorting between German and English:

'file.changeSort:after' => function ($newFile, $oldFile) {
    $lang = kirby()->language()->code() == 'en' ? 'de' : 'en';
    $newFile->save(['sort' => $newFile->sort()], $lang);
}

It is possible to disable manual file sorting via a PHP files section blueprint:

<?php

return [
	'label' => 'Files',
	'type'  => 'files',
	'template' => 'image',
	'sortable' => kirby()->language()->isDefault(),
];
<?php

use Kirby\Cms\App as Kirby;

Kirby::plugin('cookbook/programmable-blueprints', [
	'blueprints' => [
		'sections/files' => function($kirby) {
			return include __DIR__ . '/blueprints/sections/files.php';
		},
	],
]);
sections:
  files:
    extends: sections/files