Languages and UUID, how does it work?

Hi,

I’ve got a website with translation activated :
English is the default language.
French the second language.

When I create a page as a french user in the panel, kirby create a post.en.txt file with an UUID.
If I populate a field and save the page, a post.fr.txt file is created without UUID.

Why the post.fr.txt file is created without UUID?

Because the UUIDs are assigned to pages, files and users, not to translations.

Haaaa ! I thought that all txt file in the content folder was considered as page.
So here post.en.txt is the page and post.en.txt the translation which is not considered as a page by Kirby.

I asked the question because I tried to get the uuid of a page in a page.update:after hook
and $newPage->uuid() return an object with uuid NULL and I thaught Kirby was searching in the post.en.txt file.

But I’ve just realised that $oldPage->uuid() return the uuid.

Another question, $oldPage->uuid() return an object like this :

object(Kirby\Uuid\PageUuid)#1257 (3) {
    ["context"]=>
    NULL
    ["model"]=>
    object(Kirby\Cms\Page)#1190 (15) {
      ["children"]=>
      object(Kirby\Cms\Pages)#1187 (0) {
      }
      ["content"]=>
      object(Kirby\Cms\Content)#1185 (9) {
        ["title"]=>
        string(8) "Cambodge"
        ["uuid"]=>
        string(16) "UyAzweNd8WABI0DN"
        ["tripphoto"]=>
        string(0) ""
        ["tripdeparture"]=>
        string(0) ""
        ["tripdescription"]=>
        string(4) "Test"
        ["equipmentimage"]=>
        string(0) ""
        ["equipmentdescription"]=>
        string(0) ""
        ["equipmentlist"]=>
        string(0) ""
        ["existingusertrip"]=>
        string(17) "- user://ohU0Qhnn"
      }
...

So to get the uuid I need to write :

$uuid = $oldPage->content()->uuid();

And not

$uuid = $oldPage->uuid();

Do I miss something or is it the right way to get an uuid from a page object ?

Nope, the folder is the page!

This will return the UUID as string:

dump($page->uuid()->toString());

Interesting that $newPage->uuid() does not return anything, is that when u update the non-default language or the default language?

The non-default language.

I did some tests:

$newPage->uuid() return an obect but [content][uuid] is NULL as you can see below


  object(Kirby\Uuid\PageUuid)#1257 (3) {
    ["context"]=>
    NULL
    ["model"]=>
    object(Kirby\Cms\Page)#1203 (15) {
      ["children"]=>
      object(Kirby\Cms\Pages)#1262 (0) {
      }
      ["content"]=>
      object(Kirby\Cms\Content)#1247 (14) {
        ["title"]=>
        string(8) "Cambodge"
        ["uuid"]=>
        NULL
        ["tripphoto"]=>
        string(0) ""
        ["tripdeparture"]=>
        string(0) ""
        ["tripdescription"]=>
        string(4) "Test"
        ["equipmentimage"]=>
        string(0) ""
        ["equipmentdescription"]=>
        string(0) ""
        ["equipmentlist"]=>
        string(0) ""
        ["existingusertrip"]=>
        string(36) "- user://ohU0Qhnn
...

But if I use $newPage->uuid()->toString() it return the uuid !

Yes, and that makes absolute sense.

Because the uuid is not part of the content of the non-default language. So don’t use the content object in this case.