I’m using the panel.page.update
hook and would like to automatically change the URL appendix of a page on save, based on information provided in the page fields. Are there any helper functions to change a page URL, or would I have to rename the page folder using standard PHP functions?
You could use $page->move()
, but if you rename the page uid while the user is in the panel, they’ll get an error message because the link will no longer be valid.
Gah! That’s true. I suppose I could redirect the user if the URL changes, it’s not super great UX, but maybe the only way around this.
No, that won’t work, because ‘update’ happens in an AJAX request. Well I’m stuck!
You can use panel()->redirect($page, 'edit')
inside your hook after moving the page, it will then work with AJAX as well without any manual magic.
Perfect, thanks @lukasbestle and @texnixe!
For future reference, I discovered that if url: false
is set in the page blueprint’s options, $page->move($url)
does not seem to work, the $page UID will always be whatever the default is.