I am trying to build a plugin that will make it possible to copy all the pages/blocks from one language to another - to avoid the hazzle of copy-paste when creating a language like UK english from US. At the moment it is working with folders, shared blocks and pages. But somehow I can't get the internal blocks values to get copied alongside the page. I've tried debugging it and the value get's set on the new language branch of the page. But somehow when it is saved, the values are not kept. I've tried so many solutions now that I feel lost in space :)
I've removed some code for simplicity. This snippet is only for the pages.
// Loop through all pages and save em'.
foreach (var page in pages)
var pageData = contentTypeRepository.Load(page.PageTypeID);
var originalPage = page;
var newBranchPage = contentRepository
// Here newBranchPage.Property["MyInternalBlock"] will have null values on CultureSpecific properties.
newBranchPage.PageName = page.PageName;
foreach (var propertyDefinition in pageData.PropertyDefinitions)
// Regular property
newBranchPage.Property[propertyDefinition.Name].Value = originalPage.Property[propertyDefinition.Name].Value;
else if (propertyDefinition.Type.DefinitionType == typeof(PropertyBlock<BlockData>))
// We are dealing with an internal block...
var originalBlockData = originalPage.Property[propertyDefinition.Name].Value as BlockData;
var blockData = originalBlockData.CreateWritableClone();
newBranchPage.Property[propertyDefinition.Name].Value = blockData;
// Here newBranchPage.Property["MyInternalBlock"] will have correct values.
contentRepository.Save(newBranchPage, SaveAction.Publish, AccessLevel.NoAccess);
Thanks for your help. Cheers!
If I understand you correctly, you need to save internal block values. In this case, you are not supposed to create a writable clone. I think you are supposed to loop through the properties of blockData and set them on the newBranchPage (like newPage.Block.Property[xx] = oldPage.Block.Property[yy]). Since the properties of a local block exist as a part of currentPage, they need to be set on the page.
Let me know if this helps.
I have noticed the same behaviour when you use typed pages as well:
I.E. when setting the local block directly, like:
MyCustomPage.MyLocalBlockProperty = CreateNewBlock();
The values will not persist through save.
But setting the values separately, like:
MyCustomPage.MyLocalBlockProperty.Property1 = Property1Value;
Will work fine.
So, as Marija says above, don't set local blocks on page-property level.