x19
x19

Reputation: 8783

How can I customize save and publish in Umbraco back office (admin panel)?

For example, before save and publish a data,I want manipulate data (process on data) such as checking data, add an URL shorter to the UrlRewriting.config file and like these automatically.And when I deleting or unpublishing a node, I want delete the shorter URL from UrlRewriting.config file automatically. On the other hand, I want full control on saving, publishing and deleting process in Umbraco back office. PLEASE HELP ME.

Upvotes: 1

Views: 3316

Answers (2)

nologo
nologo

Reputation: 6288

Here are some examples for you:

public class SaveAndPublish : ApplicationEventHandler
{
    protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        // Content Service
        ContentService.Created += ContentService_Created;
        ContentService.Saving += ContentService_Saving;
        ContentService.Published += ContentService_Published;
        ContentService.Trashing += ContentService_Trashing;

        // Media Service
        MediaService.Saving += MediaService_Saving;
        MediaService.Saved += MediaService_Saved;
        MediaService.Trashing += MediaService_Trashing;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void ContentService_Created(IContentService sender, NewEventArgs<IContent> e)
    {
        ...
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e)
    {
        ...
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, PublishEventArgs<IContent> e)
    {            
        ...
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void ContentService_Trashing(IContentService sender, MoveEventArgs<IContent> e)
    {
        ...
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void MediaService_Saving(IMediaService sender, SaveEventArgs<IMedia> e)
    {
        ...
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void MediaService_Saved(IMediaService sender, SaveEventArgs<IMedia> e)
    {
        foreach (var entity in e.SavedEntities)
        {
            ...
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void MediaService_Trashing(IMediaService sender, MoveEventArgs<IMedia> e)
    {
        ...
    }
}

Upvotes: 3

Douglas Ludlow
Douglas Ludlow

Reputation: 10942

If you want to change the URL to the node, you can easily do so by modifying the umbracoUrlAlias property, instead of adding an entry to URLRewriting.config.

As far as adding logic when a node is saved, publish, deleted, etc., what you will do is create a class that subscribes to one or more of the many Umbraco events and perform the logic there. See Application startup events & event registration for more details.

Upvotes: 4

Related Questions