You can inspect the entities in the event data for the ContentType (Document Type) Alias and then use that to restrict your code to a specific Document Type - you can also inspect the properties to see if a specific property exists on the entity, or has a value etc.
E.g.:
void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IContent> e)
{
foreach (var article in e.SavedEntities)
{
if (article.ContentType.Alias == "Article")
{
// Check for Post Date and set to current date if not already set.
if (article.HasProperty("datePosted"))
{
DateTime? datePosted = article.GetValue<DateTime?>("datePosted");
if (!datePosted.HasValue)
article.SetValue("datePosted", DateTime.Now);
}
}
}
}
Read Only property on Umbraco doc type
I want to have a property on a doc type that is read-only (Via the Umbraco UI), I want to populate its value after the umbraco event 'Saved'
Its going to be a string, but I don't want a text box for the user to edit it.
Any ideas
Best thing in these cases is to use the Label data type.
thanks, didnt see that one :-)
Do you know how you can restrict the saved Umbraco event to fire only on one doc type?
You can inspect the entities in the event data for the ContentType (Document Type) Alias and then use that to restrict your code to a specific Document Type - you can also inspect the properties to see if a specific property exists on the entity, or has a value etc.
E.g.:
is working on a reply...