mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-16 02:36:52 +08:00
Implementing TemplateFilterForPart
Allowing devs to use parts directly for settings instead of Records --HG-- branch : 1.x
This commit is contained in:
parent
50015f11c1
commit
a27fc43e74
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
|
||||
namespace Orchard.ContentManagement.Handlers {
|
||||
public class TemplateFilterForPart<TPart> : TemplateFilterBase<ContentPart> where TPart : ContentPart, new() {
|
||||
private readonly string _prefix;
|
||||
private string _location = "Content";
|
||||
private string _position = "5";
|
||||
private readonly string _templateName;
|
||||
private string _groupId;
|
||||
|
||||
public TemplateFilterForPart(string prefix, string templateName) {
|
||||
_prefix = prefix;
|
||||
_templateName = templateName;
|
||||
}
|
||||
|
||||
public TemplateFilterForPart(string prefix, string templateName, string groupId) {
|
||||
_prefix = prefix;
|
||||
_templateName = templateName;
|
||||
_groupId = groupId;
|
||||
}
|
||||
|
||||
public TemplateFilterForPart<TPart> Location(string location) {
|
||||
_location = location;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TemplateFilterForPart<TPart> Position(string position) {
|
||||
_position = position;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TemplateFilterForPart<TPart> Group(string groupId) {
|
||||
_groupId = groupId;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override void BuildEditorShape(BuildEditorContext context, ContentPart part) {
|
||||
if (!string.Equals(_groupId, context.GroupId, StringComparison.OrdinalIgnoreCase))
|
||||
return;
|
||||
|
||||
var templatePart = part.As<TPart>();
|
||||
var templateShape = context.New.EditorTemplate(TemplateName: _templateName, Model: templatePart, Prefix: _prefix);
|
||||
context.Shape.Zones[_location].Add(templateShape, _position);
|
||||
}
|
||||
|
||||
protected override void UpdateEditorShape(UpdateEditorContext context, ContentPart part) {
|
||||
if (!string.Equals(_groupId, context.GroupId, StringComparison.OrdinalIgnoreCase))
|
||||
return;
|
||||
|
||||
var templatePart = part.As<TPart>();
|
||||
context.Updater.TryUpdateModel(templatePart, _prefix, null, null);
|
||||
BuildEditorShape(context, part);
|
||||
}
|
||||
}
|
||||
}
|
@ -153,6 +153,7 @@
|
||||
<Compile Include="ContentManagement\Aspects\ILocalizableAspect.cs" />
|
||||
<Compile Include="ContentManagement\ContentIdentity.cs" />
|
||||
<Compile Include="ContentManagement\DefaultHqlQuery.cs" />
|
||||
<Compile Include="ContentManagement\Handlers\TemplateFilterForPart.cs" />
|
||||
<Compile Include="ContentManagement\Handlers\UpdateContentContext.cs" />
|
||||
<Compile Include="ContentManagement\IHqlExpression.cs" />
|
||||
<Compile Include="ContentManagement\IHqlQuery.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user