Hello,
I am working on a project and encountered a challenge with the Files field in my blueprint. I’m looking to implement functionality similar to the “prepend” option available in the Structure field, but for the Files field. Specifically, I want new files added to a specific Files field (imagesindex
) to automatically appear at the top of the list in the panel, instead of being added to the bottom.
Here is the blueprint configuration for the imagesindex
field:
imagesindex:
label: Images/Videos
type: files
uploads: filesindex
layout: cards
size: tiny
sortBy: filename desc
text: "{{ file.structureText.isEmpty ? file.filename : file.structureText.toStructure.first.text }}"
image:
ratio: 1/1
back: "#595959"
info: "{{ file.niceSize }}"
I’ve attempted to use a file.create:after
hook to change the sort order of newly uploaded files, but it hasn’t worked as expected. My goal is for any file uploaded or chosen for this field to automatically be placed at the top of the list in the panel.
Here is an example of the hook I’ve tried:
'hooks' => [
'file.create:after' => function ($file) {
$file->changeSort(1)
}
],
However, this approach does not seem to affect the order of files in the panel. I’m looking for insights or suggestions on how to achieve this functionality. Is there a way to make the Files field behave like the Structure field with the “prepend” option, or is there a workaround that I could implement?
Any advice or guidance would be greatly appreciated!
Thank you in advance for your help!