Umbraco - 如何添加自定义通知?
我正在使用 Umbraco 4.6.2,并且需要扩展它提供的默认通知。为了这个问题,假设我正在尝试添加“取消发布”通知。
在 \umbraco\presentation\umbraco\dialogs\notifications.aspx.cs
中,它构造了从上下文菜单打开“通知”对话框时向用户显示的 checkbx 项目列表。
我发现每个 Action
都有一个 ShowInNotifier 属性 - 如何将此值设置为 true
以执行 UnPublish 操作? 这是否需要修改核心代码库,或者是否有一种很好的方法可以优雅地扩展 Umbraco?
因此,在我添加此内容后,用户可以订阅取消发布通知(我在这里是否遗漏了任何步骤?)。 现在会自动发送通知吗?
我猜不是,所以我要做的下一件事是挂钩 UnPublish 事件:
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 notifications? 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);
}
}
}
所以该代码的部分不是真实的/我需要一些指针:
这是检查用户是否是的正确方法订阅了特定通知?
如何使用默认的 umbraco 设置发送通知? (例如,像其他通知一样生成电子邮件)
如果这是不可能的,我必须构建自己的电子邮件:
如何获取存储在 umbracoSettings.config 中的发件人电子邮件地址
如何复制默认 Umbraco 通知使用的格式?我应该手动复制它还是有更好的方法来执行此操作(
感谢任何帮助(甚至只是相关示例的链接):>
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 notifications? 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 :>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的同事成功做到了这一点。
创建一个类来覆盖您希望收到通知的操作。
您可以在
/umbraco/cms/Actions
中看到所有操作。在重写的类中,您将有一个
public char Letter
。设置此项以匹配要挂钩的事件。您可以在数据库中找到每个事件的字母。将
public bool ShowInNotifier
设置为 true。就是这样!
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
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!
我通过使用 UmbracoSettings 类在 Umbraco 4.7 上实现了此功能:
http://www.java2s.com/Open-Source/CSharp/Content-Management-Systems-CMS/umbraco/umbraco/businesslogic/UmbracoSettings.cs.htm
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