mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Creating "contenttype" rule for layers
--HG-- branch : 1.x
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
@@ -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" />
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user