November Happy Hour will be moved to Thursday December 5th.

Revert to Default

Vote:
 

Hi,

 

Is it possible to "revert to default" for all properties on a pagetype without going into each property and hit the button

#66317
Feb 27, 2013 8:06
Vote:
 

In current version it is not possible, we might add that as a tool or similar.

For now you could write some code (e.g. in an admin tool) that does something like:

var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
var propertyDefinitionRepository = ServiceLocator.Current.GetInstance<IPropertyDefinitionRepository>();
var myPageType = contentTypeRepository.Load(typeof(StandardPage));

foreach (var prop in myPageType.PropertyDefinitions)
{
var writable = prop.CreateWritableClone();
writable.ResetPropertyDefinition();
propertyDefinitionRepository.Save(writable);
}

#66321
Feb 27, 2013 10:22
Vote:
 

Hi,

 

Thanks for the answer i ended up with writing a admin tool for resetting all properties on all pages

var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
var propertyDefinitionRepository = ServiceLocator.Current.GetInstance<IPropertyDefinitionRepository>();
var myPages = contentTypeRepository.List();

foreach (var myPageType in myPages)
{

foreach (var prop in myPageType.PropertyDefinitions)
{
var writable = prop.CreateWritableClone();
writable.ResetPropertyDefinition();
propertyDefinitionRepository.Save(writable);
}
}

#66349
Feb 27, 2013 14:20
Vote:
 

If you also want to make sure the ContentType (e.g. PageType) is reseted as well (now only the properties are reseted) then you could add following lines in the outer foreach loop:

var writableContentType = myPageType.CreateWritableClone() as ContentType;
writableContentType.ResetContentType();
contentTypeRepository.Save(writableContentType);

 

#66350
Feb 27, 2013 14:24
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.