mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Implementing DisableThemePart
Also implementing a new Match predicate for placement files, i.e. ContentPart="" which will apply the placement rules if the currently displayed content type contains a specific part.
This commit is contained in:
@@ -230,6 +230,7 @@ namespace Orchard.ContentTypes.Services {
|
||||
ShapeDescriptor descriptor;
|
||||
if (shapeTable.Descriptors.TryGetValue(partShapeType, out descriptor)) {
|
||||
var placementContext = new ShapePlacementContext {
|
||||
Content = context.ContentItem,
|
||||
ContentType = context.ContentItem.ContentType,
|
||||
Stereotype = stereotype,
|
||||
DisplayType = displayType,
|
||||
|
@@ -0,0 +1,23 @@
|
||||
using System.Web;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Themes.Models;
|
||||
|
||||
namespace Orchard.Themes.Drivers {
|
||||
[UsedImplicitly]
|
||||
public class DisableThemePartDriver : ContentPartDriver<DisableThemePart> {
|
||||
private readonly HttpContextBase _httpContext;
|
||||
|
||||
public DisableThemePartDriver(HttpContextBase httpContext) {
|
||||
_httpContext = httpContext;
|
||||
}
|
||||
|
||||
protected override DriverResult Display(DisableThemePart part, string displayType, dynamic shapeHelper) {
|
||||
return ContentShape("Parts_DisableTheme", () => {
|
||||
ThemeFilter.Disable(_httpContext.Request.RequestContext);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Core.Contents.Extensions;
|
||||
using Orchard.Data.Migration;
|
||||
|
||||
namespace Orchard.Themes {
|
||||
public class ThemesDataMigration : DataMigrationImpl {
|
||||
@@ -6,5 +8,14 @@ namespace Orchard.Themes {
|
||||
public int Create() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int UpdateFrom1() {
|
||||
|
||||
ContentDefinitionManager.AlterPartDefinition("DisableThemePart", builder => builder
|
||||
.Attachable()
|
||||
.WithDescription("When attached to a content type, disables the theme when a content item of this type is displayed."));
|
||||
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Themes.Models {
|
||||
/// <summary>
|
||||
/// When attached to a Content Type and rendered
|
||||
/// it will prevent the theme from being applied
|
||||
/// </summary>
|
||||
public class DisableThemePart : ContentPart {
|
||||
}
|
||||
}
|
@@ -65,9 +65,11 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Commands\ThemeCommands.cs" />
|
||||
<Compile Include="Drivers\DisableThemePartDriver.cs" />
|
||||
<Compile Include="Events\IExtensionDisplayEventHandler.cs" />
|
||||
<Compile Include="Migrations.cs" />
|
||||
<Compile Include="Models\ThemeEntry.cs" />
|
||||
<Compile Include="Models\DisableThemePart.cs" />
|
||||
<Compile Include="ResourceManifest.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Handlers\ThemeSiteSettingsPartHandler.cs" />
|
||||
@@ -103,6 +105,10 @@
|
||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||
<Name>Orchard.Framework</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Core\Orchard.Core.csproj">
|
||||
<Project>{9916839c-39fc-4ceb-a5af-89ca7e87119f}</Project>
|
||||
<Name>Orchard.Core</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Content\Web.config">
|
||||
@@ -123,6 +129,9 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\ThemeEntry.Current.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Placement.info" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
9
src/Orchard.Web/Modules/Orchard.Themes/Placement.info
Normal file
9
src/Orchard.Web/Modules/Orchard.Themes/Placement.info
Normal file
@@ -0,0 +1,9 @@
|
||||
<Placement>
|
||||
<Place Parts_DisableTheme="Content"/>
|
||||
|
||||
<!-- Opinionated, don't display the Title when disabling the theme -->
|
||||
<Match ContentPart="DisableThemePart">
|
||||
<Place Parts_Title="-"/>
|
||||
</Match>
|
||||
|
||||
</Placement>
|
@@ -128,6 +128,7 @@ namespace Orchard.ContentManagement {
|
||||
ShapeDescriptor descriptor;
|
||||
if (shapeTable.Descriptors.TryGetValue(partShapeType, out descriptor)) {
|
||||
var placementContext = new ShapePlacementContext {
|
||||
Content = context.ContentItem,
|
||||
ContentType = context.ContentItem.ContentType,
|
||||
Stereotype = stereotype,
|
||||
DisplayType = displayType,
|
||||
|
@@ -63,7 +63,8 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
ShapeDescriptor descriptor;
|
||||
if(context.ShapeTable.Descriptors.TryGetValue(editor.GetShapeType(), out descriptor)) {
|
||||
var placementContext = new ShapePlacementContext {
|
||||
ContentType = part.ContentItem.ContentType,
|
||||
Content = part.ContentItem,
|
||||
ContentType = part.ContentItem.ContentType,
|
||||
Differentiator = editor.GetDifferentiator(),
|
||||
DisplayType = null,
|
||||
Path = String.Empty
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
@@ -110,6 +111,7 @@ namespace Orchard.DisplayManagement.Descriptors {
|
||||
}
|
||||
|
||||
public class ShapePlacementContext {
|
||||
public IContent Content { get; set; }
|
||||
public string ContentType { get; set; }
|
||||
public string Stereotype { get; set; }
|
||||
public string DisplayType { get; set; }
|
||||
|
@@ -120,6 +120,10 @@ namespace Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy {
|
||||
public static Func<ShapePlacementContext, bool> BuildPredicate(Func<ShapePlacementContext, bool> predicate, KeyValuePair<string, string> term) {
|
||||
var expression = term.Value;
|
||||
switch (term.Key) {
|
||||
case "ContentPart":
|
||||
return ctx => ctx.Content != null
|
||||
&& ctx.Content.ContentItem.Parts.Any(part => part.PartDefinition.Name == expression)
|
||||
&& predicate(ctx);
|
||||
case "ContentType":
|
||||
if (expression.EndsWith("*")) {
|
||||
var prefix = expression.Substring(0, expression.Length - 1);
|
||||
|
@@ -32,7 +32,11 @@ namespace Orchard.Themes {
|
||||
|
||||
public static void Apply(RequestContext context) {
|
||||
// the value isn't important
|
||||
context.HttpContext.Items[typeof (ThemeFilter)] = null;
|
||||
context.HttpContext.Items[typeof(ThemeFilter)] = null;
|
||||
}
|
||||
|
||||
public static void Disable(RequestContext context) {
|
||||
context.HttpContext.Items.Remove(typeof(ThemeFilter));
|
||||
}
|
||||
|
||||
public static bool IsApplied(RequestContext context) {
|
||||
|
Reference in New Issue
Block a user