Jump to content
Kiwi Chris

Page clone locked page to unlocked copy by non superuser [SOLVED]

Recommended Posts

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.

  • Like 1

Share this post


Link to post
Share on other sites
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?

  • Like 1

Share this post


Link to post
Share on other sites
/*
 * 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.

 

  • Like 4

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...