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:
Suha Can
2011-05-09 10:08:00 -07:00
parent b4ec14747b
commit 891695b328
3 changed files with 46 additions and 2 deletions

View File

@@ -2,8 +2,8 @@ Name: Designer Tools
AntiForgery: enabled
Author: The Orchard Team
Website: http://orchardproject.net
Version: 1.0
OrchardVersion: 1.0
Version: 1.0.20
OrchardVersion: 1.0.20
Description: Contains designer tools to ease the Themes development process
FeatureName: Shape Tracing
Category: Designer
@@ -14,3 +14,8 @@ Features:
Name: Url Alternates
Category: Designer
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

View File

@@ -99,6 +99,10 @@
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
<Name>Orchard.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Widgets\Orchard.Widgets.csproj">
<Project>{194D3CCC-1153-474D-8176-FDE8D7D0D0BD}</Project>
<Name>Orchard.Widgets</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\AlternateController.cs" />
@@ -106,6 +110,7 @@
<Compile Include="Services\TemplatesFilter.cs" />
<Compile Include="Services\ShapeTracingFactory.cs" />
<Compile Include="Services\UrlAlternatesFactory.cs" />
<Compile Include="Services\WidgetAlternatesFactory.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\ShapeTracingWrapper.cshtml" />

View File

@@ -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);
}
}
}
});
}
}
}