果园1.7 - 创建自定义的未发布工作流活动 [英] Orchard 1.7 - Create custom Workflow Activity for Unpublished

查看:137
本文介绍了果园1.7 - 创建自定义的未发布工作流活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要挖掘到果园CMS活动的清单;未公布的活动是要求之一。我已经看了看,发现了果园默认工作流活动列表中没有一个未公开的活动。

I needed to tap into a list of activities in Orchard CMS; unpublished activity being one of the requirements. I have looked and found out that Orchard default Workflow activity list doesn't have a unpublished activity.

我已经建立了添加自己的自定义工作流活动的模块。我有没有问题创造活动,使他们的工作,但我不知道如何绑定其中的一个与事件。即使我复制发布在工作流模块默认的活动文件夹中找到活动,复制的活动没有得到绑定到任何事件。

I have built a module that add my own custom Workflow Activities. I have had no problem creating activities and making them work but I have no idea how to bind one of these with an event. Even if I copy the publish activity that is found in the default activity folder of Workflow module, the copied activity doesn't get bind to any event.

我怎样才能让这个我的活动类被称为每当有人或取消发布起草一个帖子。

How can I make it so that my activity class is called whenever someone unpublishes or drafts a post.

我也创建这里一个线程 但至今没有答案。

I have also created a thread here but so far no answers.

推荐答案

我找不到乌节CMS太大的帮助,并最终找到解决自己。我花了很多时间来得到这虽然完成。

I couldn't find much help on Orchard CMS and ended up finding a solution myself. It took me a lot of time to get this done though.

我发现的第一件事是, Orchard.Workflows.Activities 有一个文件 ContentActivity 。在这个文件中还有其他类继承了 ContentActivity ContentCreatedActivity ContentUpdatedActivity ContentPublishedActivity 。所有这些类是订阅 ContentActivity 这是一个事件活动活动。他们订阅果园核心的创建,更新和发布活动。

First thing I found was that Orchard.Workflows.Activities has a file ContentActivity. In this file there are other classes that inherits the ContentActivity class ContentCreatedActivity, ContentUpdatedActivity and ContentPublishedActivity. All these classes are activities that subscribe to ContentActivity that is an event activity. They subscribe to the Create, Update and Publish events of the Orchard core.

如果你看看 Orchard.ContentManagement.Handlers.ContentHandler 你会看到由果园CMS提供了核心默认的事件列表中。

If you look into Orchard.ContentManagement.Handlers.ContentHandler you'd see the list of default events provided by Orchard CMS core.

我感兴趣的是 OnUnpublished 事件,所以我的模块中我创建了一个会听那个事件的处理程序。

I was interested in the OnUnpublished event, so in my module I created a handler that would listen to that event.

using System.Collections.Generic;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Workflows.Services;

namespace MyModule.Handlers {
    public class WorkflowContentHandler : ContentHandler {
        public WorkflowContentHandler(IWorkflowManager workflowManager) {
            OnUnpublished<ContentPart>(
                (context, part) =>
                    workflowManager.TriggerEvent("ContentUnpublished",
                    context.ContentItem,
                    () => new Dictionary<string, object> { { 
                              "Content", context.ContentItem } }));
        }
    }
}

在这之后我们创建自定义工作流活动未公布。这个类从 ContentActivity 像它的兄弟姐妹继承,因此它可以启动工作,并会成为一个事件。

After which we create our custom workflow activity for Unpublished. This class inherits from ContentActivity like its siblings, so it can start workflow and would be an event.

using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.Localization;
using Orchard.Workflows.Models;
using Orchard.Workflows.Services;
using Orchard.Workflows.Activities;

namespace MyModule.WorkFlow
{
    public class ContentUnpublishedActivity : ContentActivity
    {
        public override string Name
        {
            get { return "ContentUnpublished"; }
        }

        public override LocalizedString Description
        {
            get { return T("Content is Unpublished."); }
        }
    }
}

就是这样。一旦你做到了这一点新的内容未公布活动将在工作流活动列表中显示出来。你可以用它配合其他活动来执行自己的工作流程的任何内容一直未公布之后。

And that's it. Once you've done this the new Content Unpublished activity would show up in the Workflow activity list. You can use it in conjunction to other Activities to execute your own workflow after any content has been unpublished.

我简直不敢相信它是如此简单。我花了3天弄明白,我是拉我的头发,我没有太多的开始。
缺乏支持和资源果园CMS真的惹恼了我一段时间。我希望这将有助于节省一些时间,谁也遇到类似问题的人。

I can't believe it was this easy. Took me 3 days to figure it out and I was pulling my hair that I don't have much of to start with. The lack of support and resources for Orchard CMS really annoys me sometime. I hope this would help save some time for anyone who has run into similar problems.

这篇关于果园1.7 - 创建自定义的未发布工作流活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆