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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...