Hi,
You can use Content Events. Like - Publishing, Published events
https://marisks.net/2017/01/22/episerver-content-events-explained/
https://world.episerver.com/blogs/Daniel-Ovaska/Dates/2019/6/content-events-in-episerver/
You can create a scheduled job, or an admin tool that will:
Or, lets say your property is of type string, and you want to set it's default value some time after adding it.
You could probably do:
[PropertyDefinitionTypePlugIn]
public class PropertyStringWithDefaultHackValue : PropertyString
{
public override object Value => base.Value ?? "Hack";
}
And then change your property on your content type to:
[Display(Name = "This should work")]
[BackingType(typeof(PropertyStringWithDefaultHackValue))]
public virtual string MyString { get; set; }
Ok tried the IInitializableModule and get an exception:
The property XXX is read-only
How do I make it writable? There is no overload called "MakeWritable" or something as far as I can see.
Note! This is a IList that I try to initiate from null in this instance.
What Tomas suggested does not work. At least not in a already custom property type. Any other ideas?
public class CustomInnerProperty
{
[Display(Order = 900, Name = "Id")]
[BackingType(typeof(StringAsGuidDescriptor))]
public virtual string Id { get; set; } = Guid.NewGuid().ToString();
}
[PropertyDefinitionTypePlugIn]
public class StringAsGuidDescriptor : PropertyString
{
public override object Value
{
get => string.IsNullOrEmpty(base.String) ? Guid.NewGuid().ToString() : base.String;
set => SetPropertyValue(value, () => base.String = value?.ToString());
}
}
public class CustomInnerPropertyDescriptor : CollectionEditorDescriptor<CustomInnerProperty>
{
public CustomInnerPropertyDescriptor()
{
GridDefinition.DisableDndSorting = true;
}
}
public class CustomOuterProperty
{
[Required]
[Display(Order = 100, Name = "Items")]
[EditorDescriptor(EditorDescriptorType = typeof(CustomInnerPropertyDescriptor))]
public virtual IList<CustomInnerProperty> Items { get; set; }
}
Hi.
I already know of SetDefaultValues on PageData, but as far as I know this only executes when the page instance is created.
Is there a way to set default properties on a page that already exists? And only if the property is NULL?