ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Separate upload- and template options in files section

Open crisgraphics opened this issue 4 years ago • 2 comments

Files section, according to the Docs: property: template, Description: Filters all files by template and also sets the template, which will be used for all uploads

Here's an example of a files field with the following select & upload options:

fields:
  cover:
    type: files
    query: page.images
    uploads:
      template: cover

and a files section on the same page:

sections:
  images:
    type: files

this section displays all files of the page, allowing me to edit / delete individual files with any template (incl. cover),
but when uploading via this section, no template will be assigned to the file.
Now the following setting

sections:
  images:
    type: files
    template: default

will assign a default template to the uploaded file, but won't display files with other templates assigned, which makes it impossible to edit / delete a file with the template cover from this section. I would need an extra files section for that.


I think, a files section with separate template and upload options (similar to a files field) could avoid having unnecessary extra files sections just for the purpose of editing / deleting files with various assigned templates.

sections:
  images:
    type: files
    uploads: default # define a template to be assigned on upload
    template: # optional (default shows all files with any template)
      - default
      - someothertemplate

Or did I miss a solution to my problem? 🤔

crisgraphics avatar Aug 11 '20 21:08 crisgraphics

If you need a workaround for the time being, you could assign a template to the files via a file.upload.after hook.

texnixe avatar Aug 12 '20 06:08 texnixe

Thanks for the suggestion, @texnixe, this means, on the frontend, I can't filter by the template anymore, if I wanted to skip the cover file, right?

foreach($page->files()->filterBy('template', 'default') as $file):
...

I would have to add an additional field in the file blueprint:

# files/cover
extraFilterField:  cover
# files/default
extraFilterField:  default

and then on the frontend:

foreach($page->files()->filterBy('extraFilterField', 'default') as $file):
...

crisgraphics avatar Aug 12 '20 08:08 crisgraphics