steirico / kirby-plugin-custom-add-fields

Custom fields for Kirby's add dialog.
MIT License
36 stars 4 forks source link

Configurate Dynamic Redirects / Slugs #58

Closed Maybach91 closed 2 years ago

Maybach91 commented 2 years ago

According to this https://github.com/steirico/kirby-plugin-custom-add-fields/tree/master#configure-redirects i can somehow set the redirection.

I have the following Model / After Page Create Hook:

class DarbietungPage extends Page {
    public static function hookPageCreate($page){
        $customSlug = $page->title()->lower() .'-'. $page->date()->toDate( '%d-%m-%Y' ); // pagetitle-2022-03-02
        // do something before a page gets deleted
        $page->changeSlug(Str::slug($customSlug));
    }
}

blueprint:

addFields:
  title:
    label: Titel
    type: text
    required: true
    icon: title
    preselect: true

  date:
    label: Datum
    help: Wann findet die Darbietung statt?
    type: date
    display: DD.MM.YYYY
    default: today
    required: true

  __dialog:
    skip: false
    redirect: true

But when i set redirect: true it tries to redirect me to darbietungen-TIMSTAMP (timestamp is default, when no slug field is there, i know)

But how can i set the slug or redirect to a dynamic value like the title and date?

Kinda related to #57

steirico commented 2 years ago

As mentioned in the readme there is a related kirby issue which is not solvable.

The only option is to not enable redirection and landing on the parent page.