mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Contribution by sfmskywalker.
As a theme developer we need to be able to override widget rendering (not widget the wrapper, but contenttypes that are sterotyped as a widget, e.g. RecentBlogPosts). This adds a new feature WidgetAlternates in the Orchard.DesignerTools module. --HG-- branch : contributions
This commit is contained in:
@@ -2,8 +2,8 @@ Name: Designer Tools
|
|||||||
AntiForgery: enabled
|
AntiForgery: enabled
|
||||||
Author: The Orchard Team
|
Author: The Orchard Team
|
||||||
Website: http://orchardproject.net
|
Website: http://orchardproject.net
|
||||||
Version: 1.0
|
Version: 1.0.20
|
||||||
OrchardVersion: 1.0
|
OrchardVersion: 1.0.20
|
||||||
Description: Contains designer tools to ease the Themes development process
|
Description: Contains designer tools to ease the Themes development process
|
||||||
FeatureName: Shape Tracing
|
FeatureName: Shape Tracing
|
||||||
Category: Designer
|
Category: Designer
|
||||||
@@ -14,3 +14,8 @@ Features:
|
|||||||
Name: Url Alternates
|
Name: Url Alternates
|
||||||
Category: Designer
|
Category: Designer
|
||||||
Description: Adds shape alternates for specific urls
|
Description: Adds shape alternates for specific urls
|
||||||
|
WidgetAlternates:
|
||||||
|
Name: Widget Alternates
|
||||||
|
Category: Designer
|
||||||
|
Description: Adds shape alternates for content types stereotyped as widgets, allowing to customize shapes by widget and zone
|
||||||
|
Dependencies: Orchard.Widgets
|
||||||
|
|||||||
@@ -99,6 +99,10 @@
|
|||||||
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
||||||
<Name>Orchard.Core</Name>
|
<Name>Orchard.Core</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\Orchard.Widgets\Orchard.Widgets.csproj">
|
||||||
|
<Project>{194D3CCC-1153-474D-8176-FDE8D7D0D0BD}</Project>
|
||||||
|
<Name>Orchard.Widgets</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Controllers\AlternateController.cs" />
|
<Compile Include="Controllers\AlternateController.cs" />
|
||||||
@@ -106,6 +110,7 @@
|
|||||||
<Compile Include="Services\TemplatesFilter.cs" />
|
<Compile Include="Services\TemplatesFilter.cs" />
|
||||||
<Compile Include="Services\ShapeTracingFactory.cs" />
|
<Compile Include="Services\ShapeTracingFactory.cs" />
|
||||||
<Compile Include="Services\UrlAlternatesFactory.cs" />
|
<Compile Include="Services\UrlAlternatesFactory.cs" />
|
||||||
|
<Compile Include="Services\WidgetAlternatesFactory.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\ShapeTracingWrapper.cshtml" />
|
<Content Include="Views\ShapeTracingWrapper.cshtml" />
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using Orchard.DisplayManagement.Implementation;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Widgets.Models;
|
||||||
|
|
||||||
|
namespace Orchard.DesignerTools.Services {
|
||||||
|
[OrchardFeature("WidgetAlternates")]
|
||||||
|
public class WidgetAlternatesFactory : ShapeDisplayEvents {
|
||||||
|
public override void Displaying(ShapeDisplayingContext context) {
|
||||||
|
context.ShapeMetadata.OnDisplaying(displayedContext => {
|
||||||
|
// We don't want the "Widget" content item itself, but the content item that consists of the Widget part (e.g. Parts.Blogs.RecentBlogPosts)
|
||||||
|
if (displayedContext.ShapeMetadata.Type != "Widget") {
|
||||||
|
ContentItem contentItem = displayedContext.Shape.ContentItem;
|
||||||
|
if (contentItem != null) {
|
||||||
|
// Is the contentItem a widget? (we could probably test for the stereotype setting, don't know if that is more efficient than selecting the WidgetPart)
|
||||||
|
var widgetPart = contentItem.As<WidgetPart>();
|
||||||
|
if (widgetPart != null) {
|
||||||
|
var zoneName = widgetPart.Zone;
|
||||||
|
var shapeName = displayedContext.ShapeMetadata.Type;
|
||||||
|
var contentTypeName = contentItem.ContentType;
|
||||||
|
|
||||||
|
// Add 2 alternates for flexible widget shape naming:
|
||||||
|
// [ShapeName]-[ZoneName].cshtml: (e.g. "Parts.Blogs.RecentBlogPosts-myZoneName.cshtml")
|
||||||
|
// [ContentTypeName]-[ZoneName].cshtml: (e.g. "RecentBlogPosts-myZoneName.cshtml")
|
||||||
|
displayedContext.ShapeMetadata.Alternates.Add(contentTypeName + "__" + zoneName);
|
||||||
|
displayedContext.ShapeMetadata.Alternates.Add(shapeName + "__" + zoneName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user