Filtering Files by Blueprint property in the File Selection Modal (k-models-dialog)

Hello,

first of all, this is the current setup for context:

Every file uploaded is stored in /content and not in the respective page folders.
I created a Filemanager plugin that enables the user to create/remove folders (not real folders in filesystem, just a list of folder-IDs).
Based on that, the user can assign each file to a folder-ID and filter by it accordingly.
The folder-ID is set in the blueprint as a select field.

      folder:
        type: select
        label: Ordner
        options:
          type: query
          query: file.folders
          text: "{{ item.name }}"
          value: "{{ item.id }}"

I also extended the k-models-dialog to include a select-field for filtering by folder-ID (together with some visual changes):

I am stuck at the file fetching part. The source code fetches the items like so:

const response = await this.$api.get(this.endpoint, params);

My first attempt was to change the params such that it fetches all items at once ( {limit: 999}, setting pagination limit to a ridiculously high number) and filtering client-side. However that does not seem to work at all. The limit is always set to 20.

Another attempt was to create a custom api endpoint for fetching files, accepting a parameter: folderID and filtering server side.

This did work fine, but then i realized that the link field also uses the same models-dialog component. Which means, i cannot select a page, since the modal only shows media items.

So i have to somehow read the type of field. Also query definitions in blueprint such as site.images or site.videos do not work, because I am not reading the blueprint data (I don’t know how).

Is there any way i can achieve the desired result? Thanks

The files field uses the limit blueprint option also for the file picker dialog. This is where that option is passed: kirby/config/fields/files.php at main · getkirby/kirby · GitHub

Thanks for responding,

right, setting the limit in the blueprint works and I could try to work around that.

Though, would it be possible to pass the limit property somehow in my custom endpoint, if i would call the source endpoint from there like so:

return [
    'pattern' => 'filemanager/modal',
    'auth' => false,
    'method' => 'POST',
    'action' => function () {
        $data = $this->requestData('body');
        $endpoint = $data['endpoint'];

        // call endpoint from here with limit param

        return ...
    }
];

I would pass the source endpoint in the request body to my custom endpoint and the custom endpoint would call the source endpoint, do some formatting including filtering.
This way i wouldn’t have to rely on manually setting the limit in the blueprint.
I guess I still don’t quite understand how the blueprint communicates with the endpoint.

Thanks anyway.