From a9ff7d597337c147c6ec0931f65ffbab6133c5fc Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Tue, 21 Jul 2015 12:06:34 +0100 Subject: [PATCH] Simplified autoroute part import and added renamed IsHomePage to PromoteToHomepage. --- .../Drivers/AutoroutePartDriver.cs | 23 ++++++------------- .../Handlers/AutoroutePartHandler.cs | 4 ++-- .../Orchard.Autoroute/Models/AutoroutePart.cs | 6 ++--- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs index 7242bd241..31c815b63 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs @@ -61,7 +61,7 @@ namespace Orchard.Autoroute.Drivers { var isHomePage = part.Id == homePageId; viewModel.IsHomePage = isHomePage; - viewModel.PromoteToHomePage = part.IsHomePage; + viewModel.PromoteToHomePage = part.PromoteToHomePage; if (settings.PerItemConfiguration) { // If enabled, the list of all available patterns is displayed, and the user can select which one to use. @@ -88,7 +88,7 @@ namespace Orchard.Autoroute.Drivers { } // Mark the content item to be the homepage. Once this content isp ublished, the home alias will be updated to point to this content item. - part.IsHomePage = viewModel.PromoteToHomePage; + part.PromoteToHomePage = viewModel.PromoteToHomePage; } return ContentShape("Parts_Autoroute_Edit", @@ -96,26 +96,17 @@ namespace Orchard.Autoroute.Drivers { } protected override void Importing(AutoroutePart part, ImportContentContext context) { - var displayAlias = context.Attribute(part.PartDefinition.Name, "Alias"); - if (displayAlias != null) { - part.DisplayAlias = displayAlias; - } - - var customPattern = context.Attribute(part.PartDefinition.Name, "CustomPattern"); - if (customPattern != null) { - part.CustomPattern = customPattern; - } - - var useCustomPattern = context.Attribute(part.PartDefinition.Name, "UseCustomPattern"); - if (useCustomPattern != null) { - part.UseCustomPattern = bool.Parse(useCustomPattern); - } + context.ImportAttribute(part.PartDefinition.Name, "Alias", s => part.DisplayAlias = s); + context.ImportAttribute(part.PartDefinition.Name, "CustomPattern", s => part.CustomPattern = s); + context.ImportAttribute(part.PartDefinition.Name, "UseCustomPattern", s => part.UseCustomPattern = XmlHelper.Parse(s)); + context.ImportAttribute(part.PartDefinition.Name, "PromoteToHomePage", s => part.PromoteToHomePage = XmlHelper.Parse(s)); } protected override void Exporting(AutoroutePart part, ExportContentContext context) { context.Element(part.PartDefinition.Name).SetAttributeValue("Alias", part.Record.DisplayAlias); context.Element(part.PartDefinition.Name).SetAttributeValue("CustomPattern", part.Record.CustomPattern); context.Element(part.PartDefinition.Name).SetAttributeValue("UseCustomPattern", part.Record.UseCustomPattern); + context.Element(part.PartDefinition.Name).SetAttributeValue("PromoteToHomePage", part.UseCustomPattern); } } } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Handlers/AutoroutePartHandler.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Handlers/AutoroutePartHandler.cs index afccd38bf..f2486e0d5 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Handlers/AutoroutePartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Handlers/AutoroutePartHandler.cs @@ -59,14 +59,14 @@ namespace Orchard.Autoroute.Handlers { ProcessAlias(part); // Should it become the home page? - if (part.IsHomePage) { + if (part.PromoteToHomePage) { // Get the current homepage an unmark it as the homepage. var currentHomePage = _homeAliasService.GetHomePage(VersionOptions.Latest); if(currentHomePage != null && currentHomePage.Id != part.Id) { var autoroutePart = currentHomePage.As(); if (autoroutePart != null) { - autoroutePart.IsHomePage = false; + autoroutePart.PromoteToHomePage = false; if(autoroutePart.IsPublished()) _orchardServices.ContentManager.Publish(autoroutePart.ContentItem); } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Models/AutoroutePart.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Models/AutoroutePart.cs index 02eb68566..ded0c98aa 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Models/AutoroutePart.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Models/AutoroutePart.cs @@ -17,9 +17,9 @@ namespace Orchard.Autoroute.Models { set { Store(x => x.DisplayAlias, value); } } - public bool IsHomePage { - get { return this.Retrieve(x => x.IsHomePage); } - set { this.Store(x => x.IsHomePage, value); } + public bool PromoteToHomePage { + get { return this.Retrieve(x => x.PromoteToHomePage); } + set { this.Store(x => x.PromoteToHomePage, value); } } public string Path {