V16 - Popup notifications in the backofice

Hi everybody, is there a built in way to send popup notifications from the backend (ApiController) to the backoffice?

I’m including my own message-objects into responses which works just fine but I’m wondering if there is already something built in so i could possibly simplify what i have going on ? :slight_smile:

Yes, you can attach messages to notification events such as content saved, updated, and more:

Here is an example, where I show a few different notifications when I save a template:

namespace Umbraco.Cms.Web.UI;

using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;

public class TemplateWarningNotification : INotificationHandler<TemplateSavingNotification>
{
    public void Handle(TemplateSavingNotification notification)
    {
        notification.Messages.Add(new EventMessage("Just some info", "Custom message", EventMessageType.Info));
        notification.Messages.Add(new EventMessage("Just an error", "Sending a notification with the error look", EventMessageType.Error));
        notification.Messages.Add(new EventMessage("Just a warning", "Another custom message", EventMessageType.Warning));
        notification.Messages.Add(new EventMessage("Just a default", "My default message", EventMessageType.Default));
        notification.Messages.Add(new EventMessage("Just a success", "Best color", EventMessageType.Success));
    }
}

I could also choose to cancel the whole operation with a message preventing the template from being saved:

        notification.CancelOperation(
            new EventMessage(
                "Error",
                "This is my custom message: Operation not allowed.",
                EventMessageType.Error));

There is a list of notifications in the docs. Hope that makes sense.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.