Content Events Reference
Overview
Section titled “Overview”IContentEvents exposes events fired during content lifecycle operations. Subscribe to “ing” events to cancel or modify operations before they complete. Subscribe to “ed” events to react after completion.
Namespace
Section titled “Namespace”Optimizely.Cms.Core
Events
Section titled “Events”Create events
Section titled “Create events”| Event | EventArgs | Cancelable | Fires when |
|---|---|---|---|
CreatingContent | ContentEventArgs | Yes | Before a new content item is persisted |
CreatedContent | ContentEventArgs | No | After a new content item is persisted |
Save events
Section titled “Save events”| Event | EventArgs | Cancelable | Fires when |
|---|---|---|---|
SavingContent | ContentEventArgs | Yes | Before content is saved |
SavedContent | ContentEventArgs | No | After content is saved |
Publish events
Section titled “Publish events”| Event | EventArgs | Cancelable | Fires when |
|---|---|---|---|
PublishingContent | ContentEventArgs | Yes | Before content is published |
PublishedContent | ContentEventArgs | No | After content is published |
Delete events
Section titled “Delete events”| Event | EventArgs | Cancelable | Fires when |
|---|---|---|---|
DeletingContent | ContentEventArgs | Yes | Before content is deleted |
DeletedContent | ContentEventArgs | No | After content is deleted |
Move events
Section titled “Move events”| Event | EventArgs | Cancelable | Fires when |
|---|---|---|---|
MovingContent | ContentEventArgs | Yes | Before content is moved |
MovedContent | ContentEventArgs | No | After content is moved |
Check-in events
Section titled “Check-in events”| Event | EventArgs | Cancelable | Fires when |
|---|---|---|---|
CheckingInContent | ContentEventArgs | Yes | Before content is checked in (draft saved) |
CheckedInContent | ContentEventArgs | No | After content is checked in |
ContentEventArgs properties
Section titled “ContentEventArgs properties”| Property | Type | Description |
|---|---|---|
Content | IContent | The content item being operated on |
ContentLink | ContentReference | Reference to the content item |
TargetLink | ContentReference | Destination reference (move/copy operations) |
CancelAction | bool | Set true in “ing” events to cancel the operation |
CancelReason | string | Message displayed when canceling |
Subscribe and cancel on validation
public class ContentEventInitializer : IConfigurableModule
{
public void ConfigureContainer(ServiceConfigurationContext context) { }
public void Initialize(InitializationEngine context)
{
var events = context.Locate.Advanced.GetInstance<IContentEvents>();
events.PublishingContent += OnPublishing;
}
public void Uninitialize(InitializationEngine context)
{
var events = context.Locate.Advanced.GetInstance<IContentEvents>();
events.PublishingContent -= OnPublishing;
}
private void OnPublishing(object? sender, ContentEventArgs e)
{
if (e.Content is ArticlePage article
&& string.IsNullOrEmpty(article.MetaDescription))
{
e.CancelAction = true;
e.CancelReason = "Meta description is required.";
}
}
} Event ordering
Section titled “Event ordering”Publish fires: SavingContent -> SavedContent -> PublishingContent -> PublishedContent. Canceling an “ing” event prevents all subsequent events in the chain.
Related
Section titled “Related”- IContentRepository Interface — Operations that trigger events
- IContent Interface — Content properties available in event args
- IPublishedStateAssessor Interface — Check publish state