When Editor cut and paste a page, then content will be simply moved from one place into another. It will get new URL, but nothing more will change. The copy and paste operation is more complicated. After Editor pasted a page, end users will be able to see a copy of the same content on the site. In some scenarios it would be good to have a better control on how exactly the content is copied. In this article I will describe my latest plugin that allows to use extended copy and paste functionality.

Site example

Let’s imagine we have a website with restaurants chain. Restaurant page type contains general information like name, description, location, type of cuisine and 50 other properties. But each restaurant page has additionally subpages:

  • menu page – with menu offered by restaurant
  • types of table pages – where user can check what kind of tables are available
  • special offers – containing latest discounts and promotions

It’s a multilanguage site that supports 4 languages. The site is already available for end users.

Below is an example of site structure.

extended content copy restaurants

For now we have only two restaurants, in Stockholm and in Warsaw. But soon we would like to open another restaurant in Stockholm. Of course we will create a separate page for it. At the beginning we should have only English version with no details about the menu and type of tables.

We can create a new restaurant page from scratch. But it would be easier for Editor to copy „Alloy Stockholm” page and reuse most of the properties. When using default copy paste functionality, there can be some issues.

Published copy

The first problem is that the page will be automatically published. End users will be able to access the copied page immediately after it was copied. To avoid this we can create a project. All items pasted in project mode are drafts. But we would have to create a project to handle just one page. It would be better to simply copy the page as draft.

There is an answer in one of the forum threads that describes how to do this by intercepting “IContentCopyHandler” service.

Language branches

Another issue is related with the fact that our site is multilanguage. When copying a page we will copy English version, but also Swedish, Spanish and French branches. This means that we won’t be able to use language fallback behaviour. We would have to translate new page to all languages from the beginning. In this case, it would be preferable to copy only in the master language.

Page children

One last thing is that when copying restaurant page we will automatically copy all descendants which in this case is menu and list of tables. So next step would be to remove all subpages. It’s not very annoying because we have only two pages to remove, but it would be nice if we will be able to copy only restaurant page.

Extended content copy plugin

After a short introduction describing an example scenario, I can show a new addon. It solves the issues described above.

Plugin allows to:

  • keep version as draft instead of copying published version
  • copy only master language of the page
  • do not copy descendants of the page

How to use an addon

The plugin can be used in two ways. We can either override the default behaviour of the paste command or we can show new “Extended paste” action in page tree context menu.

New action in context menu

In this mode, when Editor copies a page, the new command “Extended paste” will be available after clicking the context menu of the destination page:

extended copy command

After clicking the command, the dialog with available options will be displayed

extended copy dialog

In the restaurant example we can copy page with all options unselected. Copied page won’t be published nor translated, but also menu and tables pages won’t be copied.

using extended content copy command

Below you can see how it works when copying all descendants as drafts:

using extended copy descendants

Options

Addon has few settings that are stored as Options. They define how extended paste behaves.

Option Type Description Default value
Mode Enum Defines how plugin is working:

  • off – plugin is not used
  • command – new edit mode command is available
  • auto – build-in paste command will automatically use configured paste options
Command
AllowedPasteActions AllowedActions Defines what actions are active: PublishOnDestination, CopyAllLanguageBranches and CopyDescendants PublishOnDestination, CopyAllLanguageBranches, CopyDescendants are true
PasteDefaults Defaults Defines default action values PublishOnDestination is false while CopyAllLanguageBranches and CopyDescendants are true

Below you can find an example for configuring options:

Overriding default copy behaviour

When Mode is set to auto, the edit mode command is not available. Editor won’t be able to decide how copy should work, but instead it will depend on configured Defaults values.

Below you can see how automatic mode is working for copying unpublished pages.

extended copy using automatic mode

Source code is available on Github

There is also nuget package