Remove unwanted language versions from Sitecore subtree

This post ties nicely into the idea thats shown in /automatically-set-the-language-of-the-content-editor

If you have a multi site solution, chances are each site has a finite set of languages available to it. In this example we have one language per site ala:

– sitecore
– Content
— English site – field with value for default language set to be ‘en’
— French site – field with value for default language set to be ‘fr-fr’

Its easy to create invalid language content under each site. This not only bloats the amount of data being stored but can also be quite misleading, its easy to edit content on the wrong language.

The code below demonstrates a Sitecore command which allows these invalid items to be purged from the tree.

It assumes the website root item has a template with a known ID (WebsiteTemplate) and on this item there is a shared droplist field: Default Language which has its source set to /sitecore/system/Languages

This is then patched into the Sitecore commands via:

You can then setup a new button in your ribbon by creating a new item in core. In this example, within the versions chunk of the ribbon:
/sitecore/content/Applications/Content Editor/Ribbons/Chunks/Versions/

You need to fill out ‘Click’ to be item:purgeversions and then choose the icon you want.

By overriding the QueryState function the button only shows if:

  • You are below a website root item
  • You are on the valid language set on the website root item <- this is really cool since it means you can only remove invalid language versions

Taking this forwards, if you had multiple languages per site you’d need to update some of the logic to deal with lists of languages rather than 1 language.

Leave a Reply

Your email address will not be published. Required fields are marked *