Step 1: Add Integration Point & Module
With Sitecore PowerShell (SPE), there are multiple integration points available that may be added to modules. In this case, we need to add it as a Chunk in Presentation Ribbon.
- Add PowerShell Script Module in Script Library folder with a name. Example: Sample
- In the newly Sample PowerShell Script Module item, add a Integration Point Libraries. This will open a window to select the integration points. In this dialog, choose Content Editor - Ribbon. This will add the ribbons which are available in this system as Script Library.
- In the Presentation item, add a PowerShell Script Library called Merge Layout. This will be the name of the chunk in the Presentation ribbon. And then add a PowerShell script item called Final to Shared. We can set an icon in the Appearance section of this item to match with the purpose of this button. In this case, we are merging the layout so I chose Arrow merge (/~/icon/office/32x32/arrow_merge.png).
- In the script body, we can add this simple script to get the current item and then call Merge-Layout command. The Merge-Layout command takes all the layout information stored in the FinalLayout field and merges into the SharedLayout field. The FinalLayout field is reset after the merge completes. This will be done only in the current language. In case if other languages are having final layout, additional script should be added to remove the Final Renderings field values in other languages.
- We can add Show Rule as "Where the item has a layout". We can also add Enable Rule to be specific to ACL of the project. For non-admins to use this button, I suggest to add whether the item is locked and locked by me. This will let the non-admins to run this script without any issues.
- In order to remove all the empty Ribbon libraries, go to Sample PowerShell Script Module item, right click, scripts, Purge Empty Libraries. This will remove all the empty Script Libraries.
Some integrations need to be synced with the Core database through the PowerShell ISE.
- Open Sitecore PowerShell ISE from Launch Page.
- Go to Settings Ribbon, Rebuild All button, Sync Library with Content Editor Ribbon. This will sync the newly created integration to sync with Core database.
Nehemiah, thanks for this post. This issue has bothered us for years.
ReplyDeleteMay I suggest a couple of changes?
The language issue can be addressed by changing the script to '$SitecoreContextItem | Merge-Layout' as this grabs the language and version of the selected item.
Also, adding an 'Enable Rule' that checks whether the '__Final Renderings' field is empty lets the user see whether there is an issue for the selected item. If there are no Final Renderings, the button is disabled.