Saturday, 8 April 2017

Adding Delete subitems action to Sitecore Context Menu

Leave a Comment
I have been working with Sitecore Data Exchange Framework 1.3 and got into a situation where I wanted to remove all subitems of a specific item without deleting that specific item. For example, let’s consider the below screenshot of Sitecore content tree:
I am working on CD Catalog Pipeline Batch item of Sitecore Data Exchange Framework 1.3 and whenever I click on Run Pipeline Batch button available in Data Exchange Ribbon, it creates multiple items under CD Catalog item from XML file. I am developing and testing custom XML provider for Data Exchange framework thus there is a frequent need to delete all subitems under CD Catalog item except CD Catalog item folder. If I right click on CD Catalog item then Sitecore Context Menu gives me option to delete CD Catalog item which will eventually delete all subitems under it but I don’t want to delete CD Catalog item folder.

Although Sitecore provides an option to delete subitems of a particular item.  In this case, I have to follow below steps:
  1. I have to navigate away from current item CD Catalog Pipeline Batch and have to select CD Catalog item in content tree. 
  2. I have to make sure that HOME ribbon is selected. Click on Delete subitems button available in Operations chunk.
I prefer to delete items using Context Menu Delete action rather than HOME ribbon Delete action because I don’t want to navigate away from my current item and I am not always working on HOME ribbon. I like customizing Sitecore client interface to fit my personal requirements and to speed up the development. Adding Delete subitems functionality to Sitecore Context Menu is easy. Follow below steps to add Delete subitems functionality to Sitecore Context Menu:
  1. Login into Sitecore Client and select Core database.
  2. Navigate to /sitecore/content/Applications/Content Editor/Context Menues/Default/Delete
  3. You will find item:delete(id=$Target) in Message field. Clear the content of Message field. 
  4. Create a new child item under /sitecore/content/Applications/Content Editor/Context Menues/Default/Delete node using template /sitecore/templates/System/Menus/Menu item. Set item name as Delete.
  5. Enter item:delete(id=$Target) in Message field and set Display name as Delete. Also set Icon field.
  6. Create a new child item under /sitecore/content/Applications/Content Editor/Context Menues/Default/Delete node using template /sitecore/templates/System/Menus/Menu item. Set item name as Delete Subitems.
  7. Enter item:deletechildren(id=$Target) in Message field and set Display name as Delete Subitems. Also set Icon field.
  8. Navigate to Master database and right click on CD Catalog item. You will notice Delete Subitems action is available in Sitecore context menu.
Comments and suggestions are most welcome. Happy coding!

0 comments :

Post a comment