Jump to content

Move page in API


MarkE
 Share

Recommended Posts

I've googled a fair bit but can't find anywhere an API method to move a page to be under a new parent. Obviously this would have to handle naming conflicts. Is there one? Or a module? Or just a code snippet ? 

Thanks

Link to comment
Share on other sites

Thanks - that's effectively what I was doing, except in a before Pages::save hook, thus:

$p = $event->arguments(0);
//..some code here ..//
$p->parent = pages()->get('/news/');
$event->arguments(0, $p);

It works fine so long as the name does not already exist under the new parent. I seem to recall that the core uses a routine to add -1, -2 etc. but I can't find it.

Link to comment
Share on other sites

Thanks - that's what I was looking for. Here is my final code for the hook:

$p->name = $this->pages->names()->uniquePageName($p->name);
$p->parent = pages()->get('/news/');
$event->arguments(0, $p);

Works a treat!

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...