Kirby3 AutoID - unique ID for pages, files and structures to create safe relations

I am creating posts for my plugins to make it easier to find them using the forum search and not just the docs search.

My AutoID Plugin adds an automatic unique ID for Pages, Files and nested Structures including performant helpers to retrieve them to your Kirby installation. Bonus: Tiny-URL.

Kirby does not (yet) have a persistent unique id for Page- and File-Objects, which could be useful in various situations. Using the $page->id() will not solve this since it changes when the $page->slug() / $page->url() changes, Files could get renamed. What would be needed was a Field defined in Page/File Blueprints where that unique id will be stored and some logic to generate it automatically (using Hooks). Thus the idea of autoid was born.

To sum it up with the AutoID Plugin you can solve problems like these:

  • Automatically get an unique id for each Page/File which has the autoid Field in its Blueprint.
  • Store a reference to a Page/File which does not break if that objects or parents are renamed.
  • Get a Page/File quickly using that reference.
 content:
  type: fields
  fields:
    text:
      type: textarea
    autoid:             # <-------
      type: autoid  
special:
  label: Special Child
  type: checkboxes
  options: query
  query:
    fetch: page.children.filterBy("template", "special")
    text: "{{ page.title }}"
    value: "{{ page.AUTOID }}" # uppercase is recommended
$autoid = 'any-autoid-value';

$result = autoid($autoid); // global helper function
// or
$result = $page->myFieldWithAutoIDReference()->fromAutoID(); // fieldMethod

if(is_a($result, 'Kirby\Cms\Page')) {
    // got a Page
} elseif(is_a($result, 'Kirby\Cms\File')) {
    // got a File
} elseif(is_a($result, 'Kirby\Cms\StructureObject')) {
    // got a StructureObject
    // $result->myFieldname()
    // $result->id: $autoid
    // $result->parent: Site|Page-Object hosting the Structure
}

Hello @bnomei

I’m inheriting an old kirby site (v 3.10) with your old autoid plugin.

I’d like to delete it because it’s not maintain anymore and uuid exists.

Could you help me and tell me how to replace in the code such line to avoid calling the autoid() function but instead using kirby’s native function?

autoid('blog')->children()->listed()->sortBy('pubDate', 'desc');

Thank you

something like this? Migration Autoid to Kirby UUIDs

Thank you for pointing me this script.

Unfortunately, it’s not working as I’m explaining in the other thread.

Also, I beleive this script will replace autoid value in all content by uuuid value.

However, my question was more about the autoid() function. How to replace the usage of autoid() function?

I guess, i should replace

autoid('blog')->children()->listed()->sortBy('pubDate', 'desc');

by something like

uuid('blog')->children()->listed()->sortBy('pubDate', 'desc');

in the code but I didn’t find such uuid() function neither the equivalent to your autoid() function. Any idea?