Kiwi Chris Posted August 19, 2019 Share Posted August 19, 2019 I want to be able to allow users with page clone rights the ability to clone locked pages with specified templates to a new unlocked copy, but without letting them edit the locked page. It looks as though I have the right permissions set to allow them to copy a page, but I need to add a hook in the /site/ready.php to unlock a page after it's copied. What method should I hook into? Edit: Figured it out. AddHookAfter Pages::Cloned. I had to be careful to pick the right argument though so that I was modifying the cloned copy and not the page that the copy was made from. 1 Link to comment Share on other sites More sharing options...
szabesz Posted August 20, 2019 Share Posted August 20, 2019 20 hours ago, Kiwi Chris said: Edit: Figured it out. AddHookAfter Pages::Cloned. I had to be careful to pick the right argument though so that I was modifying the cloned copy and not the page that the copy was made from. Hello, Will you please share a code snippet for future reference so that others can clearly see what to watch out for? 1 Link to comment Share on other sites More sharing options...
Kiwi Chris Posted August 20, 2019 Author Share Posted August 20, 2019 /* * Example of how to clone a locked page, remove the lock on the copy, and clear the value of a field in the copy. * Reset stockCode Field when copying a page using a specific template, also remove locked status. * This code is included in the /site/ready.php file. */ $wire->addHookAfter('Pages::cloned', function($event) { /* * Important: The event arguments include both the copied page and the newly created page. * Don't use $event->arguments('page') as this returns the page that is being cloned rather than the cloned copy. * Instead use $event->arguments(1) which correctly refers to the new copy. */ $currentPage = $event->arguments(1); if ($currentPage->template == 'bom') { $currentPage->stockCode = ''; $currentPage->status = $currentPage->status & ~Page::statusLocked; //probably better to use removeStatus(Page::statusLocked) $currentPage->save(array('quiet' => true)); } }); Here's my documented example of how I got this to work. 4 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now