Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom events code to update a Component on localize

I'm writing some custom events code in SDL Tridion 2011 SP 1-1 which modifies a Component's field on save or localize, during the initialization phase:

var localize = EventSystem.Subscribe<Component, LocalizeEventArgs>(OnComponentLocalize, EventPhases.Initiated);
var save = EventSystem.Subscribe<Component, SaveEventArgs>(OnComponentSave, EventPhases.Initiated);
_subscriptions.Add(localize);
_subscriptions.Add(save);

The save event works fine but the same code doesn't work on the localize event - any changes made to the Component's XML are being discarded. I'm using pretty straightforward code:

var fields = new ItemFields(component.Content, component.Schema);
var translatedSummary = fields["summary"] as MultiLineTextField;
translatedSummary.Value = translation;
component.Content = fields.ToXml();

The only way I can get the changes to persist on localization is if I do it in a Post / Commit phase and do a check out / update & save / check in. This isn't great as it takes a few seconds to execute & does it in a separate transaction after the Component has been localized. Does anyone know of a more elegent way to do this?

like image 776
richeym Avatar asked Dec 03 '12 16:12

richeym


1 Answers

I think the action of localizing will only change the the blueprint status of the item, and give you version #1 of the item in the new publication. I don't think you can make any modifications to that item without creating a new version (i.e. version 2).

This seems to be what you have found. I'm think your only option (which you have already discovered) will be to modify and re-save the item after he localization has occurred.

like image 153
Chris Summers Avatar answered Oct 10 '22 03:10

Chris Summers