Here is an another example. What I am not happy that reflection and message collection are being used. But it can be as workaround for quick solution.
Configuration:
<sitecore>
<commands>
<command name="custom:CopyLatestVersionTo" type="Sitecore.CopyTo.CopyLatestVersionTo, Sitecore.CopyTo" />
</commands>
<processors>
<uiCopyItems>
<processor mode="on" type="Sitecore.CopyTo.Pipelines.CopyLatestTo, Sitecore.CopyTo" method="OnlyLatestVersion" patch:after="processor[@type='Sitecore.Shell.Framework.Pipelines.CopyItems,Sitecore.Kernel'][@method='Execute']" />
</uiCopyItems>
</processors>
Command:
[Serializable]
public class CopyLatestVersionTo : Sitecore.Shell.Framework.Commands.CopyTo
{
public override void Execute(CommandContext context)
{
var args = new CopyItemsArgs();
var instance = Activator.CreateInstance(typeof(Sitecore.Shell.Framework.Items));
var methodInfos = new List<MethodInfo>(instance.GetType().GetMethods(BindingFlags.Static | BindingFlags.NonPublic));
var method = methodInfos.FirstOrDefault(m => m.Name == "Start" && m.GetParameters().Length == 4);
args.AddMessage("command:copylatest");
method.Invoke(instance, new object[] {"uiCopyItems", args, context.Items[0].Database, context.Items});
}
}
Processor:
public class CopyLatestTo
{
protected virtual void OnlyLatestVersion(CopyItemsArgs args)
{
var pipelineMessages = args.GetMessages(PipelineMessageFilter.Informations);
if (pipelineMessages != null && pipelineMessages.Any(m=>m.Text == "command:copylatest"))
{
var copies = args.Copies;
foreach (var copy in copies)
{
var currentVersion = copy.Versions.GetLatestVersion();
foreach (var itemVersion in copy.Versions.GetVersions(true))
{
if (!itemVersion.Version.Number.Equals(currentVersion.Version.Number))
{
itemVersion.Versions.RemoveVersion();
}
}
}
}
}
}
Menu Item:
"/sitecore/content/Applications/Content Editor/Context Menues/Default/Copying/Copy Latest To"


Result:
