Hi! I'm trying to set default values to a page. If the page already exists in another language (SE) I want to fetch the value from a specific property on that version and copy that to the corresponding property on the EN version. Is this possible? I'm unable to resolve the ContentReference in the SetDefaultValues() method, since it's not saved, but I hope there is another way around this?! Thanks!
You could attach an eventhandler to IContentEvents.CreatingContentLanguage and in the event handler load the other language and then copy property values from that language version.
Thanks Johan! Unfortunately I'm using epi cms 9.x, which doesn't seem to have CreatingContentLanguage. I guess I'm stuck with an event like PublishingContent and to automatically create all languages when creating the master language version and in that process copy values to the other language versions, do you agree?
It depends on which behaviour you want for the editors. With your suggestion when someone publish one language version then all the other languages would be created automatically. If you instead want to have the behaviour that the editor create the language versions them self then you could attach an event handler to IContentEvents.SavingContent and there check if it is a new language branch and if so copy the values from master language. Something like:
public void Initialize(InitializationEngine context)
context.Locate.Advanced.GetInstance<IContentEvents>().SavingContent += (o, args) =>
if (args.Content is ILocalizable localizable)
var existingLanguages = localizable.ExistingLanguages;
var language = localizable.Language;
if (existingLanguages.Any() && !existingLanguages.Contains(language))
//new language version
var masterLanguageVersion = context.Locate.Advanced.GetInstance<IContentLoader>().Get<IContent>(args.ContentLink, localizable.MasterLanguage);
//Copyvalues to args.Content
If I understand your requirement correctly and you're looking to create a language version as a copy of the master language version you could use the language manager plugin. This gives you a gadget in one of the side panels which lists all languages available with a "create" link next to any which don't have a language version set up yet. When you click "create" it gives you the option of either starting from a blank page or copying values from the master version.
Thanks Johan, that's actually a great solution! :)
Paul, you are absolutely right! In my case (didn't mention this in the post) I also want to make a tiny modification of the content, otherwise your solution would be the preferred one. Thanks!
Best regards, Erik