ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Pages, files, users field: `value` option

Open texnixe opened this issue 6 years ago • 8 comments

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 avatar Feb 12 '19 12:02 texnixe

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

texnixe avatar Jul 14 '19 10:07 texnixe

Maybe we should do it analog to checkboxes or select?

 query:
    fetch: page.files
    value: "{{ file.autoid }}"

distantnative avatar May 06 '20 16:05 distantnative

Yes, that would be best.

texnixe avatar May 06 '20 18:05 texnixe

Something new about that?

illycz avatar Jul 11 '20 20:07 illycz

Any update here? Feature would be much appreciated.

jonasfeige avatar Aug 29 '20 16:08 jonasfeige

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

afbora avatar Aug 29 '20 18:08 afbora

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

fabianmichael avatar Sep 17 '20 10:09 fabianmichael

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!

dinko avatar Nov 20 '20 08:11 dinko