storypioneers / kirby-selector

file selector panel field for Kirby CMS
GNU General Public License v3.0
128 stars 23 forks source link

Add option to select source for files #31

Open bravokiloecho opened 9 years ago

bravokiloecho commented 9 years ago

Would it be possible to add an option which would filter the available files to a particular source, eg:

As a use case, let's say you have collection of different banner images in the site section which are available from every page using the site file method. Then on each new page, you use the Selector field to show all the available banner images so that the user can select which one to use on this page.

This plugin is an extremely useful tool and I would hope something like the above would be a useful addition. Thanks for your consideration!

JonasDoebertin commented 9 years ago

Generally I think it would be a nice enhancement to implement this.

We could utilize a new query blueprint option that could be set to:

However, the selector stores only the filename of the chosen file. That means there's no way of figuring out what page (if not the current) the selected file comes from within the templates. This is something to keep in mind.

Since this option would be a quite advanced one though, I don't think this is a real stopper.

@bravokiloecho What do you think?

bravokiloecho commented 9 years ago

I think your query blueprint option is a great idea! Thanks so much for considering the suggestion.

As for not having access to the source page location from the template, does this mean that the output of the selector field won't be a full uri to the file?

Or do you just mean the template won't have access to something like the value of the blueprint option?

If the latter, I agree this isn't really a large concern. And for the use case described above it wouldn't be a problem I don't think.

JonasDoebertin commented 9 years ago

As for not having access to the source page location from the template, does this mean that the output of the selector field won't be a full uri to the file?

This is the way the selector currently works. It only stores the filename and not the complete path or url. Generally, if you need the complete url, you'd have to do something like this right now:

$url = $page->files()->find($page->mySelectorField())->url(); // the "old" way

$url = $page->mySelectorField()->toFile()->url(); // as of Kirby 2.1

If you choose to let the selector display site files, you would need to do something like this in your templates:

$url = $site->files()->find($page->mySelectorField())->url();

Similar if you display files from another page:

$url = $site->find('custom/page/uri')->files()->find($page->mySelectorField())->url();
bravokiloecho commented 9 years ago

Ok I see, thanks for clarifying.

I guess that isn't so problematic and wouldn't be a block on the usefulness of this kind of feature.

Just a thought, and I have no idea how possible this is, but would be possible for the selector to return an array containing the filename and some relevant options, rather than just the filename? So that, for example, if you'd specified the source of the images as the Site page, you could then query that option when you called the field and use it to set the full path for the file.