Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

SetDefaultValues from published version of other language?

Vote:
 

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!

/Erik

#191750
Edited, Apr 27, 2018 11:33
Vote:
 

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.

#191752
Apr 27, 2018 11:46
Vote:
 

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?

Br Erik

#191799
Apr 28, 2018 7:19
Vote:
 

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
                    }
                    
                }
            };
        }
#191808
Apr 30, 2018 8:07
Vote:
 

Hi Erik,

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.

Paul

#191816
Apr 30, 2018 11:05
Vote:
 

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

#191818
Edited, Apr 30, 2018 11:25
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.