mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +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 {
|
namespace Orchard.Core.Contents.Handlers {
|
||||||
|
|
||||||
public interface IRulesManager : IEventHandler
|
public interface IRulesManager : IEventHandler {
|
||||||
{
|
|
||||||
void TriggerEvent(string category, string type, Func<Dictionary<string, object>> tokensContext);
|
void TriggerEvent(string category, string type, Func<Dictionary<string, object>> tokensContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
[OrchardFeature("Orchard.Core.Contents.Rules")]
|
[OrchardFeature("Contents.Rules")]
|
||||||
public class RulePartHandler : ContentHandler
|
public class RulePartHandler : ContentHandler {
|
||||||
{
|
public RulePartHandler(IRulesManager rulesManager) {
|
||||||
public RulePartHandler(IRulesManager rulesManager)
|
|
||||||
{
|
|
||||||
|
|
||||||
OnPublished<ContentPart>(
|
OnPublished<ContentPart>(
|
||||||
(context, part) =>
|
(context, part) =>
|
||||||
@@ -26,7 +23,7 @@ namespace Orchard.Core.Contents.Handlers {
|
|||||||
OnPublished<ContentPart>(
|
OnPublished<ContentPart>(
|
||||||
(context, part) =>
|
(context, part) =>
|
||||||
rulesManager.TriggerEvent("Content", "Published",
|
rulesManager.TriggerEvent("Content", "Published",
|
||||||
() => new Dictionary<string, object> { { "Content", context.ContentItem } } ));
|
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
|
||||||
|
|
||||||
OnRemoved<ContentPart>(
|
OnRemoved<ContentPart>(
|
||||||
(context, part) =>
|
(context, part) =>
|
||||||
@@ -35,7 +32,7 @@ namespace Orchard.Core.Contents.Handlers {
|
|||||||
|
|
||||||
OnVersioned<ContentPart>(
|
OnVersioned<ContentPart>(
|
||||||
(context, part1, part2) =>
|
(context, part1, part2) =>
|
||||||
rulesManager.TriggerEvent("Content", "Versioned",
|
rulesManager.TriggerEvent("Content", "Versioned",
|
||||||
() => new Dictionary<string, object> { { "Content", part1.ContentItem } }));
|
() => new Dictionary<string, object> { { "Content", part1.ContentItem } }));
|
||||||
|
|
||||||
OnCreated<ContentPart>(
|
OnCreated<ContentPart>(
|
||||||
|
@@ -14,4 +14,4 @@ Features:
|
|||||||
Name: Contents Rules
|
Name: Contents Rules
|
||||||
Description: Rules for the Contents modules
|
Description: Rules for the Contents modules
|
||||||
Category: Rules
|
Category: Rules
|
||||||
Dependency: Rules
|
Dependency: Orchard.Rules, Contents
|
||||||
|
@@ -5,58 +5,49 @@ using Orchard.Environment.Extensions;
|
|||||||
using Orchard.Events;
|
using Orchard.Events;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
|
||||||
namespace Orchard.Core.Contents.Rules
|
namespace Orchard.Core.Contents.Rules {
|
||||||
{
|
public interface IEventProvider : IEventHandler {
|
||||||
public interface IEventProvider : IEventHandler
|
|
||||||
{
|
|
||||||
void Describe(dynamic describe);
|
void Describe(dynamic describe);
|
||||||
}
|
}
|
||||||
|
|
||||||
[OrchardFeature("Contents.Rules")]
|
[OrchardFeature("Contents.Rules")]
|
||||||
public class ContentEvents : IEventProvider
|
public class ContentEvents : IEventProvider {
|
||||||
{
|
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public void Describe(dynamic describe)
|
public void Describe(dynamic describe) {
|
||||||
{
|
|
||||||
Func<dynamic, bool> contentHasPart = ContentHasPart;
|
Func<dynamic, bool> contentHasPart = ContentHasPart;
|
||||||
|
|
||||||
describe.For("Content", T("Content Items"), T("Content Items"))
|
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("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("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("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("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"];
|
var contenttypes = context.Properties["contenttypes"];
|
||||||
|
|
||||||
if(String.IsNullOrEmpty(contenttypes))
|
if (String.IsNullOrEmpty(contenttypes)) {
|
||||||
{
|
|
||||||
return T("Any").Text;
|
return T("Any").Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
return contenttypes;
|
return contenttypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ContentHasPart(dynamic context)
|
private static bool ContentHasPart(dynamic context) {
|
||||||
{
|
|
||||||
string contenttypes = context.Properties["contenttypes"];
|
string contenttypes = context.Properties["contenttypes"];
|
||||||
var content = context.Tokens["Content"] as IContent;
|
var content = context.Tokens["Content"] as IContent;
|
||||||
|
|
||||||
// "" means 'any'
|
// "" means 'any'
|
||||||
if(String.IsNullOrEmpty(contenttypes))
|
if (String.IsNullOrEmpty(contenttypes)) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(content == null)
|
if (content == null) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var contentTypes = contenttypes.Split(new [] {','} );
|
var contentTypes = contenttypes.Split(new[] { ',' });
|
||||||
|
|
||||||
return contentTypes.Any(contentType => content.ContentItem.TypeDefinition.Name == contentType);
|
return contentTypes.Any(contentType => content.ContentItem.TypeDefinition.Name == contentType);
|
||||||
}
|
}
|
||||||
|
@@ -6,31 +6,26 @@ using Orchard.Environment.Extensions;
|
|||||||
using Orchard.Events;
|
using Orchard.Events;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
|
||||||
namespace Orchard.Core.Contents.Rules
|
namespace Orchard.Core.Contents.Rules {
|
||||||
{
|
public interface IFormProvider : IEventHandler {
|
||||||
public interface IFormProvider : IEventHandler
|
|
||||||
{
|
|
||||||
void Describe(dynamic context);
|
void Describe(dynamic context);
|
||||||
}
|
}
|
||||||
|
|
||||||
[OrchardFeature("Contents.Rules")]
|
[OrchardFeature("Contents.Rules")]
|
||||||
public class ContentForms : IFormProvider
|
public class ContentForms : IFormProvider {
|
||||||
{
|
|
||||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
protected dynamic Shape { get; set; }
|
protected dynamic Shape { get; set; }
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public ContentForms(
|
public ContentForms(
|
||||||
IShapeFactory shapeFactory,
|
IShapeFactory shapeFactory,
|
||||||
IContentDefinitionManager contentDefinitionManager)
|
IContentDefinitionManager contentDefinitionManager) {
|
||||||
{
|
|
||||||
_contentDefinitionManager = contentDefinitionManager;
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
Shape = shapeFactory;
|
Shape = shapeFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Describe(dynamic context)
|
public void Describe(dynamic context) {
|
||||||
{
|
Func<IShapeFactory, dynamic> form =
|
||||||
Func<IShapeFactory, dynamic> form =
|
|
||||||
shape => {
|
shape => {
|
||||||
|
|
||||||
var f = Shape.Form(
|
var f = Shape.Form(
|
||||||
@@ -46,8 +41,7 @@ namespace Orchard.Core.Contents.Rules
|
|||||||
|
|
||||||
f._Parts.Add(new SelectListItem { Value = "", Text = T("Any").Text });
|
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 });
|
f._Parts.Add(new SelectListItem { Value = contentType.Name, Text = contentType.DisplayName });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,4 +15,4 @@ Features:
|
|||||||
Name: Comments Rules
|
Name: Comments Rules
|
||||||
Description: Rules for the Comments modules
|
Description: Rules for the Comments modules
|
||||||
Category: Rules
|
Category: Rules
|
||||||
Dependency: Rules
|
Dependency: Orchard.Comments, Orchard.Rules
|
Reference in New Issue
Block a user