Change Slug in 'page.create:after' Hook

Hi,

I have to change the slug in page.create:after hook.

For testing purposes, the hook is very simple:

    'hooks' => [
        'page.create:after' => function ($page) {
            $page->changeSlug("ma-new-slug");
        }
    ]

After adding a new page (slug set to my-old-slug), the hook is executed and the slug is changed. But the response send back to the panel does not reflect the changed slug:

01

Any ideas to get around this?

a custom page create method as suggested Here by @lukaskleinschmidt worked for me.

1 Like

Great, thanks to you both, @lukaskleinschmidt and @moeli.

Has anybody a “real world” example how to include this? My tryouts failed and I wanted to do exactly the same …

  'hooks' => [
      'page.create:after' => function($page) {
        if ( str::startsWith($page->intendedTemplate(), 'block-' ) ) {
          $page->changeSlug('xxxxx');
        }
      }
    ]

Always returns in errors …