AI OnAI Off
Hi Palle,
I don't think this would be possible, however you may perfer to hook in to the 'SavingContent' event. Whenever you make changes Optimizely will save the content automatically in the background.
Attaching and event listener to this event will allow you to validate the content and raise a message to the user.
The following is for creating content however the same could be applied to the savingcontent event.
private void ContentEvents_CreatingContent(object sender, EPiServer.ContentEventArgs e)
{
if (e.Content is ImageFile imageFile && imageFile.BinaryData != null)
{
using (var blobData = imageFile.BinaryData.OpenRead())
{
int.TryParse(ConfigurationManager.AppSettings["ImageMaxFileSize"], out var imageMaxFileSize);
if (imageMaxFileSize <= 0)
{
imageMaxFileSize = 1024;
}
if (blobData.Length > imageMaxFileSize)
{
e.CancelAction = true;
e.CancelReason = string.Format(new FilesizeFormatProvider(), "Filesize exceeds the maximum allowed {0:fs}", imageMaxFileSize);
}
}
}
}
Example I would like to validate state of blocks in a contentarea (for example are they all published) and show warnings if nessecarry on LoadedContent (not on SavedContent or PublishingContent ... like IValidate<TContent>)