mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Fixing feature name for RulesHandler
--HG-- branch : 1.x
This commit is contained in:
@@ -7,16 +7,13 @@ using Orchard.Events;
|
||||
|
||||
namespace Orchard.Core.Contents.Handlers {
|
||||
|
||||
public interface IRulesManager : IEventHandler
|
||||
{
|
||||
public interface IRulesManager : IEventHandler {
|
||||
void TriggerEvent(string category, string type, Func<Dictionary<string, object>> tokensContext);
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Core.Contents.Rules")]
|
||||
public class RulePartHandler : ContentHandler
|
||||
{
|
||||
public RulePartHandler(IRulesManager rulesManager)
|
||||
{
|
||||
[OrchardFeature("Contents.Rules")]
|
||||
public class RulePartHandler : ContentHandler {
|
||||
public RulePartHandler(IRulesManager rulesManager) {
|
||||
|
||||
OnPublished<ContentPart>(
|
||||
(context, part) =>
|
||||
@@ -26,7 +23,7 @@ namespace Orchard.Core.Contents.Handlers {
|
||||
OnPublished<ContentPart>(
|
||||
(context, part) =>
|
||||
rulesManager.TriggerEvent("Content", "Published",
|
||||
() => new Dictionary<string, object> { { "Content", context.ContentItem } } ));
|
||||
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
|
||||
|
||||
OnRemoved<ContentPart>(
|
||||
(context, part) =>
|
||||
@@ -35,7 +32,7 @@ namespace Orchard.Core.Contents.Handlers {
|
||||
|
||||
OnVersioned<ContentPart>(
|
||||
(context, part1, part2) =>
|
||||
rulesManager.TriggerEvent("Content", "Versioned",
|
||||
rulesManager.TriggerEvent("Content", "Versioned",
|
||||
() => new Dictionary<string, object> { { "Content", part1.ContentItem } }));
|
||||
|
||||
OnCreated<ContentPart>(
|
||||
|
@@ -14,4 +14,4 @@ Features:
|
||||
Name: Contents Rules
|
||||
Description: Rules for the Contents modules
|
||||
Category: Rules
|
||||
Dependency: Rules
|
||||
Dependency: Orchard.Rules, Contents
|
||||
|
@@ -5,58 +5,49 @@ using Orchard.Environment.Extensions;
|
||||
using Orchard.Events;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Core.Contents.Rules
|
||||
{
|
||||
public interface IEventProvider : IEventHandler
|
||||
{
|
||||
namespace Orchard.Core.Contents.Rules {
|
||||
public interface IEventProvider : IEventHandler {
|
||||
void Describe(dynamic describe);
|
||||
}
|
||||
|
||||
[OrchardFeature("Contents.Rules")]
|
||||
public class ContentEvents : IEventProvider
|
||||
{
|
||||
public class ContentEvents : IEventProvider {
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public void Describe(dynamic describe)
|
||||
{
|
||||
public void Describe(dynamic describe) {
|
||||
Func<dynamic, bool> contentHasPart = ContentHasPart;
|
||||
|
||||
describe.For("Content", T("Content Items"), T("Content Items"))
|
||||
.Element("Created", T("Content Created"), T("Content is actually created."), contentHasPart, (Func<dynamic, LocalizedString>) (context => T("When content with types ({0}) is created.", FormatPartsList(context))), "SelectContentTypes")
|
||||
.Element("Versioned", T("Content Versioned"), T("Content is actually versioned."), contentHasPart, (Func<dynamic, LocalizedString>) (context => T("When content with types ({0}) is versioned.", FormatPartsList(context))), "SelectContentTypes")
|
||||
.Element("Published", T("Content Published"), T("Content is actually published."), contentHasPart, (Func<dynamic, LocalizedString>) (context => T("When content with types ({0}) is published.", FormatPartsList(context))), "SelectContentTypes")
|
||||
.Element("Removed", T("Content Removed"), T("Content is actually removed."), contentHasPart, (Func<dynamic, LocalizedString>) (context => T("When content with types ({0}) is removed.", FormatPartsList(context))), "SelectContentTypes");
|
||||
.Element("Created", T("Content Created"), T("Content is actually created."), contentHasPart, (Func<dynamic, LocalizedString>)(context => T("When content with types ({0}) is created.", FormatPartsList(context))), "SelectContentTypes")
|
||||
.Element("Versioned", T("Content Versioned"), T("Content is actually versioned."), contentHasPart, (Func<dynamic, LocalizedString>)(context => T("When content with types ({0}) is versioned.", FormatPartsList(context))), "SelectContentTypes")
|
||||
.Element("Published", T("Content Published"), T("Content is actually published."), contentHasPart, (Func<dynamic, LocalizedString>)(context => T("When content with types ({0}) is published.", FormatPartsList(context))), "SelectContentTypes")
|
||||
.Element("Removed", T("Content Removed"), T("Content is actually removed."), contentHasPart, (Func<dynamic, LocalizedString>)(context => T("When content with types ({0}) is removed.", FormatPartsList(context))), "SelectContentTypes");
|
||||
}
|
||||
|
||||
private string FormatPartsList(dynamic context)
|
||||
{
|
||||
private string FormatPartsList(dynamic context) {
|
||||
var contenttypes = context.Properties["contenttypes"];
|
||||
|
||||
if(String.IsNullOrEmpty(contenttypes))
|
||||
{
|
||||
if (String.IsNullOrEmpty(contenttypes)) {
|
||||
return T("Any").Text;
|
||||
}
|
||||
|
||||
return contenttypes;
|
||||
}
|
||||
|
||||
private static bool ContentHasPart(dynamic context)
|
||||
{
|
||||
private static bool ContentHasPart(dynamic context) {
|
||||
string contenttypes = context.Properties["contenttypes"];
|
||||
var content = context.Tokens["Content"] as IContent;
|
||||
|
||||
// "" means 'any'
|
||||
if(String.IsNullOrEmpty(contenttypes))
|
||||
{
|
||||
if (String.IsNullOrEmpty(contenttypes)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(content == null)
|
||||
{
|
||||
if (content == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var contentTypes = contenttypes.Split(new [] {','} );
|
||||
var contentTypes = contenttypes.Split(new[] { ',' });
|
||||
|
||||
return contentTypes.Any(contentType => content.ContentItem.TypeDefinition.Name == contentType);
|
||||
}
|
||||
|
@@ -6,31 +6,26 @@ using Orchard.Environment.Extensions;
|
||||
using Orchard.Events;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Core.Contents.Rules
|
||||
{
|
||||
public interface IFormProvider : IEventHandler
|
||||
{
|
||||
namespace Orchard.Core.Contents.Rules {
|
||||
public interface IFormProvider : IEventHandler {
|
||||
void Describe(dynamic context);
|
||||
}
|
||||
|
||||
[OrchardFeature("Contents.Rules")]
|
||||
public class ContentForms : IFormProvider
|
||||
{
|
||||
public class ContentForms : IFormProvider {
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
protected dynamic Shape { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ContentForms(
|
||||
IShapeFactory shapeFactory,
|
||||
IContentDefinitionManager contentDefinitionManager)
|
||||
{
|
||||
IContentDefinitionManager contentDefinitionManager) {
|
||||
_contentDefinitionManager = contentDefinitionManager;
|
||||
Shape = shapeFactory;
|
||||
}
|
||||
|
||||
public void Describe(dynamic context)
|
||||
{
|
||||
Func<IShapeFactory, dynamic> form =
|
||||
public void Describe(dynamic context) {
|
||||
Func<IShapeFactory, dynamic> form =
|
||||
shape => {
|
||||
|
||||
var f = Shape.Form(
|
||||
@@ -46,8 +41,7 @@ namespace Orchard.Core.Contents.Rules
|
||||
|
||||
f._Parts.Add(new SelectListItem { Value = "", Text = T("Any").Text });
|
||||
|
||||
foreach (var contentType in _contentDefinitionManager.ListTypeDefinitions())
|
||||
{
|
||||
foreach (var contentType in _contentDefinitionManager.ListTypeDefinitions()) {
|
||||
f._Parts.Add(new SelectListItem { Value = contentType.Name, Text = contentType.DisplayName });
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user