I want to write a simple notification handler that will maintain the published state of a copied node. So if the original node was published in English and Arabic I want it to also be published in those language on the new node.
Please note this could cause unwanted consequences. It works in my case as I am going to turn it off after I have create several copies of the tree for different regions.
public void Handle(ContentCopiedNotification notification)
{
if (notification.Original.Published)
{
var publishedCultures = notification.Original.PublishedCultures;
if (publishedCultures != null && publishedCultures.Any())
{
var culturesToPublish = publishedCultures.ToArray();
_contentService.SaveAndPublish(notification.Copy, culturesToPublish);
}
}
}
I don’t know how your users are using the system, but I just want to add that this could be a dangerous game to play: you may be publishing content that is still in draft on the other cultures.
It’s not a long term or ongoing solution, it is just whilst preparing the content to be in a different structure. I have the this mapped to a config setting so I can turn it off.
The code above respects the published status of the different languages now and only publishes the ones that are published on the original node.
Good stuff Paul! I am always a bit scared when people post code that people might copy before considering the impact, so I wanted to leave a note for future readers.