Jump to content

Adding a clone button to Page Edit

Robin S

Recommended Posts

If you have the core ProcessPageClone module installed you can copy a page via Page List:



But sometimes I don't want to hunt around through Page List to find the page I want to copy, and instead I have found the page via the admin search and have it open in Page Edit. So I used this hook in /site/ready.php to add a "Clone this page" button to the bottom of the Settings tab.


// Add a clone button to the Settings tab of Page Edit if this page is allowed to be cloned
$wire->addHookAfter('ProcessPageEdit::buildFormSettings', function(HookEvent $event) {
	$wrapper = $event->return;
	$modules = $event->wire()->modules;
	$page = $event->process->getPage();
	/** @var ProcessPageClone $ppc */
	$ppc = $modules->get('ProcessPageClone');
	if($page && $ppc->hasPermission($page)) {
		/** @var InputfieldButton $f */
		$f = $modules->get('InputfieldButton');
		$f->value = 'Clone this page';
		$f->href = $event->wire()->config->urls->admin . 'page/clone/?id=' . $page->id;

Maybe somebody else has this need and finds this useful.

  • Like 9
Link to comment
Share on other sites

Also, I want to open the page in Page Edit after it is cloned. Here is a hook for that:

// Edit the cloned page after it is created
$wire->addHookBefore('ProcessPageClone::execute', function(HookEvent $event) {
	$event->wire()->addHookBefore('Session::redirect', function(HookEvent $event) {
		$url = $event->arguments(0);
		$id = (int) filter_var($url, FILTER_SANITIZE_NUMBER_INT);
		$redirect_url = $event->wire()->config->urls->admin . 'page/edit/?id=' . $id;
		$event->arguments(0, $redirect_url);


  • Like 3
Link to comment
Share on other sites

  • 4 months later...

This is what I am using:

    $this->wire->addHookAfter('ProcessPageEdit::getSubmitActions', function($event) {
      $page = $event->process->getPage();
      if($page->template != "foo") return;
      $actions = $event->return;

      $actions['clone'] = [
        'value' => 'clone',
        'icon' => 'clone',
        'label' => 'Save + create copy',

      $event->return = $actions;

    $this->wire->addHookAfter('ProcessPageEdit::processSubmitAction', function($event) {
      $action = $event->arguments(0); // action name, i.e. 'hello'
      $page = $event->process->getPage(); // Page that was edited/saved
      if($page->template != 'foo') return;

      if($action === 'clone') {
        $copy = $this->wire->pages->clone($page);
        $copy->title .= ' (copy ' . uniqid() . ')';


  • Like 2
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...