Thank you very much for your great cms! I really love the new unique id system in Kirby 3.8. Before this feature I used the the AutoID-plugin by bnomei. AutoID also works in structure fields. The new native feature also seems to be integrated in structures:
The Uuid classes provide an interface to connect identifiable models (page, file, site, user, blocks, structure entries) with a dedicated UUID string.
But I’m not sure how to use the UUID in the structure field.
districts:
label:
en: Districts
de: Bezirke
type: structure
fields:
name:
label:
en: Name
de: Name
type: text
width: 1/4
sortBy: name DESC
parks:
label: Parks
type: structure
fields:
name:
label:
en: Name
de: Name
type: text
district:
label:
en: District
de: Bezirk
type: select
options:
type: query
query: site.districts.toStructure
text: "{{ structureItem.name }}"
value: "{{ structureItem.uuid }}"
But I can’t find any uuid in the site.txt-file, where is the structure stored:
No, I can’t tell. We would like to implement it as soon as possible, but UUIDs for structure fields are a bit tricky and need careful planning, that’s why they haven’t made it into 3.8.0 yet.
Looks like you can still use the AutoID plugin. Here’s a quote from Bruno:
only the very latest autoid release is blocking k3.8 and that is ONLY if you use composer to install it. if you hardwire plugin v2.8.1 or download the zip you can keep using that even with k3.8 i decided create 2.8.2 with blocking k3.8 to emphasize that uuids are core now. (edited)
Is this still planned for the near future? I ran into an issue with the autoid plugin and php 8.2 yesterday so want to remove it from a site I’m maintaining. Thought I’d ask before I write my own plugin to deal with structure UUIDs.
Here’s an update for Kirby 4.5. Simply add a hidden field to the blueprint:
uuid:
type: hidden
Then, create a hook for site.update:after, page.update:after, or similar events. Below is an example of a hook. You only need to adjust it to fit your specific needs:
use Kirby\Data\Data;
use Kirby\Uuid\Uuid;
return [
'site.update:after' => function (Kirby\Cms\Site $newSite, Kirby\Cms\Site $oldSite) {
$employees = $newSite->employees()->yaml();
foreach ($employees as $item) {
// Check if a valid UUID already exists
if (empty($item['uuid'])) {
$item['uuid'] = Uuid::generate();
}
}
$newSite->save([
'employees' => Data::encode($employees, "yaml"),
]);
}
];
Important Note
It’s crucial to include the hidden field in the blueprint. Without it, the hook will continuously generate and save a new UUID every time an update occurs.
Please note that this forum is in English, we don’t really want people to start adding translations for all sorts of languages following your example. Thanks for your understanding .