开发者

Umbraco - how to add a custom notification?

开发者 https://www.devze.com 2023-02-17 20:03 出处:网络
I\'m using Umbraco 4.6.2, and need to extend the default notifications it provides. For the sake of this question, let\'s say I am trying to add an \"Unpublish\" notification.

I'm using Umbraco 4.6.2, and need to extend the default notifications it provides. For the sake of this question, let's say I am trying to add an "Unpublish" notification.

In \umbraco\presentation\umbraco\dialogs\notifications.aspx.cs it constructs the list of checkbx items shown to the user when opening the "Notifications" dialogue from the context menu.

I see that each Action has a ShowInNotifier property - how can I set this value to true for the UnPublish action? Does this require modifying the core codebase, or is there a nice way I can gracefully extend Umbraco?

So after I have added this, users can subscribe to the UnPublish notification (am I missing any steps here?). Will this automagically send notifications now?

I'm guessing not, so the next thing I have done is hooked the UnPublish event:

public class CustomEvents : ApplicationBase
{
    public CustomEvents()
    {
        Document.AfterUnPublish += new Document.UnPublishEventHandler(Document_AfterUnPublish);
    }

    void Document_AfterUnPublish(Document sender, umbraco.cms.businesslogic.UnPublishEventArgs e)
    {
        var user = User.GetCurrent();

        if (!string.IsNullOrEmpty(user.Email) && user.GetNotifications(sender.Path).Contains("UnPublish"))
        {
            //Send a notification here using default Umbraco settings, or, construct email and send manually:
            string umbracoNotificationSenderAddress = "";   //How to get the address stored in umbracoSettings.config -> <notifications> -> <email>

            //How to use the same subject/message formats used for other no开发者_开发知识库tifications? With the links back to the content?
            string subject = "Notification of UnPublish performed on " + MyUtilities.GetFriendlyName(sender.Id);
            string message = MyUtilities.GetFriendlyName(sender.Id) + " has just been unpublished.";

            umbraco.library.SendMail(umbracoNotificationSenderAddress, user.Email, subject, message, true);
        }
    }
}

So the bits of that code that are not real/I need some pointers on:

  • Is that the correct way for checking if a user is subscribed to a particular notification?

  • How can I send a notification using the default umbraco settings? (e.g. generate an email just like the other notifications)

If that is not possible and I must construct my own email:

  • How do I get the from email address stored in umbracoSettings.config that

  • How can I copy the formatting used by the default Umbraco notifications? Should I manually copy it or is there a nicer way to do this (programmatically).

Any help (or even just links to relevant examples) are appreciated :>


My colleague got this working.

Create a class that overrides the action you wish to have notifications for. You can see all the actions in /umbraco/cms/Actions

public class ActionUnPublishOverride : umbraco.BusinessLogic.Actions.ActionUnPublish, IAction
{
    ... see what the other actions look like to find out what to put in here!

In the overridden class, you will have a public char Letter. Set this to match the event to hook into. You can find the letters each event has in the database.

Set the public bool ShowInNotifier to true.

That's it!


I've got this working on Umbraco 4.7 by using the UmbracoSettings class:

http://www.java2s.com/Open-Source/CSharp/Content-Management-Systems-CMS/umbraco/umbraco/businesslogic/UmbracoSettings.cs.htm

umbraco.library.SendMail(umbraco.UmbracoSettings.NotificationEmailSender, newMember.Email, "email subject", "email body", false);
0

精彩评论

暂无评论...
验证码 换一张
取 消