Revert to Default

 

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
  • Johan Björnfot
    Member since: 2004
     

    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
  •  

    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
  • Johan Björnfot
    Member since: 2004
     

    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