What Sitecore standard copy functionality does:
- Copies the whole item tree under the selected item
- Copies all item versions (if you have more)
- All references (included the datasources in your components) remain the same
So in some cases it is good but especially when you have pages with local component datasources the standard copy function does not really for you.
To solve this problem implemented the following solution but it has some prerequisites:
- The Page item should have folder item named Content, the the item identicated as a Page
- The Content folder should contain all local datasource items for the actual Page
What this button does?
- Creates a new item from the selected item with the Content item recursively
- Creates new language versions from the last version of the selected Page item
- Sets the new item’s datasource references in the Final Layout and Shared Layout
- Sets the new item’s rule action datasource references in the Final Layout and Shared Layout
At first I have the following config which registers a command for the button in Content Editor and a processor which does the main job.
Here we have the command which calls the pipeline.
Here is the referenced pipeline.
As you can see it calls the another service class where I have implemented the main logic.
I have some extra class which are the model and constant classes.
At the end create a button in the Core database.
- Path: /sitecore/content/Applications/Content Editor/Ribbons/Chunks/Operations
- Name: Copy Page To
- Click field: skeleton:copypage
Aaaand here is the new button!