If you want to make changes to an entity (i.e. Content, Media etc...) before it's saved, or when something new is added or deleted. You can use the IBeforeEntitySave plugin.
Just implement the Interface
/// <summary>/// Defines a contract for handling operations that need to occur before saving an entity to the database./// </summary>publicinterfaceIBeforeEntitySave{ /// <summary> /// Gets the type of the entity that the implementor of this interface is concerned with during the save operation. /// </summary>Type EntityType { get; } /// <summary> /// Executes operations needed before saving an entity to the database. /// </summary> /// <typeparamname="T">The type of the entity being saved.</typeparam> /// <paramname="entity">The entity instance that is about to be saved.</param> /// <paramname="entityState">The state of the entity within the context (e.g., Added, Modified, Deleted).</param> /// <returns>Returns false if the save operation should be canceled; otherwise, true.</returns>boolBeforeSave<T>(T entity,EntityState entityState);}
And then you can check the entity state or just just update the entity before it's saved. Very simple example below showing the save being abandoned
publicclassStopSaveIfBadWord:IBeforeEntitySave{publicType EntityType =>typeof(Content);publicboolBeforeSave<T>(T entity,EntityState entityState) {if (entity isContent content) {if (content.Name!=null&&content.Name.Contains("Arsenal")) { // Horrible word so don't let them savereturnfalse; } }returntrue; }}