getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.26k stars 166 forks source link

page.uuid cannot be used in blueprint definitions in multi-lang setups #4955

Open hariom147 opened 1 year ago

hariom147 commented 1 year ago

Description

When adding {{ page.uuid }} to a blueprint (anywhere, i.e. in the text property of the info field or the help property of any field I tried), the add page dialog throws a duplicate error, even though the page slug does not exist. The page is created nonetheless: After cancelling the dialog and refreshing the panel the created page shows. Only happens when 'languages'=> true is set in config.

Expected behavior
Add a new page through pages section in the panel without error.

Screenshots

Bildschirm­foto 2022-12-14 um 22 37 25

To reproduce

  1. install fresh starterkit

  2. enable languages in config

  3. add page.uuid to page blueprint i.e.

    fields:
    test:
    type: info
    text: "{{ page.uuid }}"
  4. From pages section create a new page that has page.uuid in its blueprint

  5. See error

Your setup

Kirby Version
3.8.3

Console output
XHRPOSThttp://starterkit.test/panel/dialogs/pages/create?language=en [HTTP/1.1 400 Bad Request 29ms]

POST http://starterkit.test/panel/dialogs/pages/create?language=en Status 400 Bad Request VersionHTTP/1.1 Übertragen406 B (145 B Größe) Referrer Policysame-origin Anfrage-PrioritätHighest

Cache-Control
    no-store, private
Connection
    keep-alive
Content-Type
    application/json; charset=UTF-8
Date
    Fri, 16 Dec 2022 12:47:36 GMT
Server
    nginx/1.23.2
Transfer-Encoding
    chunked
X-Fiber
    true
X-Powered-By
    PHP/8.1.13

Accept
    */*
Accept-Encoding
    gzip, deflate
Accept-Language
    de,en-US;q=0.7,en;q=0.3
Cache-Control
    no-cache
Connection
    keep-alive
Content-Length
    72
Content-Type
    text/plain;charset=UTF-8
Cookie
    kirby_session=ecafab31991a13734302b2895694415ef3aa09de%2B1672404442.c7760f7f8bf57b3fafc0.f3521b151bc46c42e64d821b8633be831483e8bff171a3caa8e34ab2d2006771
Host
    starterkit.test
Origin
    http://starterkit.test
Pragma
    no-cache
Referer
    http://starterkit.test/panel/site
User-Agent
    Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:107.0) Gecko/20100101 Firefox/107.0
X-CSRF
    f5784bc2719486f3b79492777f5ba0dffde7c975c0b2ef48ca0d8aa991446ba9
X-Fiber
    true
X-Fiber-Globals
    false
X-Fiber-Only

X-Fiber-Referrer
    /site

Your system (please complete the following information)

afbora commented 1 year ago

Summary

You are guessing this problem. Uuid processes start before the page is created (via form class, mentioned below related lines) and the non-existent page is saved with ModelUuid::storeId(). When it's time for the actual page creation, the error returns because the page has already created.

https://github.com/getkirby/kirby/blob/3.8.3/src/Cms/PageActions.php#L539-L543 https://github.com/getkirby/kirby/blob/3.8.3/src/Uuid/ModelUuid.php#L121

Also this is working on 3.8.0 but not for 3.8.1.1, 3.8.2 and 3.8.3. ~So it's regression.~ Because we have added UUIDs for multilanguage in 3.8.1.1. So this should be bug instead regression.

bastianallgeier commented 1 year ago

It's unfortunately a lot more complex than we hoped, but there's a simple workaround for now:

info:
  type: info
  text: "{{ page.content.get('uuid') }}"  

We are working on getting this fixed permanently in one of the next major versions.

mynameisfreedom commented 7 months ago

The same issue happens with {{ page.permalink }}, is there maybe a workaround for that too?

afbora commented 7 months ago

@mynameisfreedom As workaround you can use like that:

{{ kirby.url('base') }}/@/page/{{ page.content.get('uuid') }}

Also you use custom page methods: {{ page.myCustomPermalink }} that use $page->content()->get('uuid') instead $page->uuid().

mynameisfreedom commented 7 months ago

You are a Kirby beast @afbora 💪

Thank you, that works 🚀