From f35b33fb9bf5156877bac3245dd40a5640403448 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 3 Jan 2014 18:30:44 -0800 Subject: [PATCH] Allowing templates to override themes' shapes --- .../Services/TemplateBindingStrategy.cs | 14 +++++++++++++- .../Descriptors/DefaultShapeTableManager.cs | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Templates/Services/TemplateBindingStrategy.cs b/src/Orchard.Web/Modules/Orchard.Templates/Services/TemplateBindingStrategy.cs index 71dceff60..36855060f 100644 --- a/src/Orchard.Web/Modules/Orchard.Templates/Services/TemplateBindingStrategy.cs +++ b/src/Orchard.Web/Modules/Orchard.Templates/Services/TemplateBindingStrategy.cs @@ -35,12 +35,24 @@ namespace Orchard.Templates.Services { }) .ToList(); + // Use a fake theme descriptor which will ensure the shape is used over + // any other extension. It's also necessary to define them in the Admin + // theme in order to process tokens + + var fakeThemeDescriptor = new FeatureDescriptor { + Id = "", // so that the binding is not filtered out + Priority = 10, // so that it's higher than the themes' priority + Extension = new ExtensionDescriptor { + ExtensionType = DefaultExtensionTypes.Theme, // so that the binding is overriding modules + } + }; + foreach (var record in shapes) { _templateProvider.Set(record.Name, record.Template); var shapeType = AdjustName(record.Name); builder.Describe(shapeType) - .From(new Feature { Descriptor = Feature.Descriptor }) + .From(new Feature { Descriptor = fakeThemeDescriptor }) .BoundAs("Template::" + shapeType, descriptor => context => { var template = _templateProvider.Get(record.Name); diff --git a/src/Orchard/DisplayManagement/Descriptors/DefaultShapeTableManager.cs b/src/Orchard/DisplayManagement/Descriptors/DefaultShapeTableManager.cs index 82a751da5..3243e160a 100644 --- a/src/Orchard/DisplayManagement/Descriptors/DefaultShapeTableManager.cs +++ b/src/Orchard/DisplayManagement/Descriptors/DefaultShapeTableManager.cs @@ -107,7 +107,7 @@ namespace Orchard.DisplayManagement.Descriptors { if (DefaultExtensionTypes.IsTheme(extensionType)) { // alterations from themes must be from the given theme or a base theme var featureName = alteration.Feature.Descriptor.Id; - return featureName == themeName || IsBaseTheme(featureName, themeName); + return String.IsNullOrEmpty(featureName) || featureName == themeName || IsBaseTheme(featureName, themeName); } return false;