Multilingual site - copy node and maintain published state

Hi all

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 can you help?

Kind regards

Paul

I managed to solve it myself.

:warning: 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. :warning:

    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);
            }
        }
    }
1 Like

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.

Hi Seb

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.

Kind regards

Paul

1 Like

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.

I’ve edited the solution to add a warning

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.