getkirby / ideas

This is the backlog of ideas and feature requests from the last two years. Use our new feedback platform to post your new ideas or vote on existing ideas.
https://feedback.getkirby.com
20 stars 0 forks source link

Pages, files, users field: `value` option #193

Open texnixe opened 5 years ago

texnixe commented 5 years ago

This would be useful when using the AutoID plugin to store unique references to a page. Currently, we have to use a select type of field to achieve this.

texnixe commented 5 years ago

The same option would make sense for the files field and there is already an issue for the users field.

distantnative commented 4 years ago

Maybe we should do it analog to checkboxes or select?

 query:
    fetch: page.files
    value: "{{ file.autoid }}"
texnixe commented 4 years ago

Yes, that would be best.

illycz commented 4 years ago

Something new about that?

jonasfeige commented 4 years ago

Any update here? Feature would be much appreciated.

afbora commented 4 years ago

@jonasfeige You can give priority to the feature by upvoting.

fabianmichael commented 4 years ago

I accidently added another issue for this topic just yesterday (see https://github.com/getkirby/ideas/issues/609).

TL;DR: Using just a value property won’t work technically, as the picker also need a ways of efficently fetching the selected pages/files when displaying the field.

If the pages field e.g. uses AutoID or anything else but the full page ID, it would need to go through the entire site tree, evaluate the query defined in the field’s value property for every single page (worst-case) to find the selected page(s). It would propably need a dedicated extension type or at least a callback function that can handle both getting the identifier or getting a page by identifier. For the files field however, this would be a bit easier, as the field just needs to check a page’s children. But nevertheless, this would be much easier on the backend to use a callback that can handle all the logic involved.

There are probably not so many options that really make sense to store when selecting something from a picker field, as one usually needs a unique identifier:

  1. ID: The full page/file ID
  2. UID/filename: Just the UID of a given page or filename without full path. Only works, if the field’s parent model is known.
  3. UUID: A global, unique identifier as defined by a plugin, e.g. AutoID by @bnomei.

(Rough) Example:

# site/plugins/autoid/index.php
<?php 

Kirby::plugin('my/plugin', [
  'resolver' => [
    'autoid' => function ($idOrModel, $parent = null) {
      if (is_object($idOrModel)) {
        // Object given, return its AutoID
        return $idOrModel->AUTOID();
      }
      // string given, fetch page/file
      return autoid($idOrModel);
    },
  ],
]);
# site/blueprints/fields/page.yml

type: pages
label: Subpage
resolver: autoid
dinko commented 3 years ago

I'm looking for exactly this as I'm saving related pages of an article. If a pages' IDs or UIDs change often, it could become a maintenance nightmare. I'd love something like auto id / a UUID to be in Kirby's core.

@fabianmichael, does your rough example already work as you described it? Tried it, but no success, I might be doing something wrong, though. Thänx!