Creating "contenttype" rule for layers

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2013-02-11 11:39:54 -08:00
parent 9bd01cf7e8
commit 9bc2f26a96
3 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
using System.Collections.ObjectModel;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Widgets.Handlers {
/// <summary>
/// Saves references to content items which have been displayed during a request
/// </summary>
public class DisplayedContentItemDetailHandler : ContentHandler, IDisplayedContentItemHandler {
private readonly Collection<string> _contentTypes = new Collection<string>();
protected override void BuildDisplayShape(BuildDisplayContext context) {
if (context.DisplayType == "Detail") {
_contentTypes.Add(context.ContentItem.ContentType);
}
}
public bool IsDisplayed(string contentType) {
return _contentTypes.Contains(contentType);
}
}
public interface IDisplayedContentItemHandler: IDependency {
bool IsDisplayed(string contentType);
}
}

View File

@@ -63,6 +63,7 @@
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="ControlWrapper.cs" />
<Compile Include="Drivers\LayerPartDriver.cs" />
<Compile Include="Handlers\DisplayedContentItemHandler.cs" />
<Compile Include="Handlers\LayerHintHandler.cs" />
<Compile Include="Drivers\WidgetPartDriver.cs" />
<Compile Include="Migrations.cs" />
@@ -78,6 +79,7 @@
<Compile Include="ResourceManifest.cs" />
<Compile Include="RuleEngine\AuthenticatedRuleProvider.cs" />
<Compile Include="RuleEngine\BuiltinRuleProvider.cs" />
<Compile Include="RuleEngine\ContentDisplayedRuleProvider.cs" />
<Compile Include="RuleEngine\RuleManager.cs" />
<Compile Include="RuleEngine\UrlRuleProvider.cs" />
<Compile Include="Services\IRuleManager.cs" />

View File

@@ -0,0 +1,23 @@
using System;
using Orchard.Widgets.Handlers;
using Orchard.Widgets.Services;
namespace Orchard.Widgets.RuleEngine {
public class ContentDisplayedRuleProvider : IRuleProvider {
private readonly IDisplayedContentItemHandler _displayedContentItemHandler;
public ContentDisplayedRuleProvider(IDisplayedContentItemHandler displayedContentItemHandler) {
_displayedContentItemHandler = displayedContentItemHandler;
}
public void Process(RuleContext ruleContext) {
if (!String.Equals(ruleContext.FunctionName, "contenttype", StringComparison.OrdinalIgnoreCase)) {
return;
}
var contentType = Convert.ToString(ruleContext.Arguments[0]);
ruleContext.Result = _displayedContentItemHandler.IsDisplayed(contentType);
}
}
}