mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
#5337: Fixed homepage becoming lost after publishing layout template being used by the homepage.
Work Item: 5337
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
using Orchard.ContentManagement;
|
||||
using System;
|
||||
using Orchard.Alias;
|
||||
using Orchard.Autoroute.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Data;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Layouts.Models;
|
||||
using Orchard.Layouts.Services;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Layouts.Handlers {
|
||||
public class LayoutPartHandler : ContentHandler {
|
||||
@@ -13,6 +17,7 @@ namespace Orchard.Layouts.Handlers {
|
||||
private readonly IShapeDisplay _shapeDisplay;
|
||||
private readonly ILayoutSerializer _serializer;
|
||||
private readonly IStaticHttpContextScopeFactory _staticHttpContextScopeFactory;
|
||||
private readonly IAliasService _aliasService;
|
||||
|
||||
public LayoutPartHandler(
|
||||
IRepository<LayoutPartRecord> repository,
|
||||
@@ -21,7 +26,8 @@ namespace Orchard.Layouts.Handlers {
|
||||
IContentPartDisplay contentPartDisplay,
|
||||
IShapeDisplay shapeDisplay,
|
||||
ILayoutSerializer serializer,
|
||||
IStaticHttpContextScopeFactory staticHttpContextScopeFactory) {
|
||||
IStaticHttpContextScopeFactory staticHttpContextScopeFactory,
|
||||
IAliasService aliasService) {
|
||||
|
||||
_layoutManager = layoutManager;
|
||||
_contentManager = contentManager;
|
||||
@@ -29,6 +35,7 @@ namespace Orchard.Layouts.Handlers {
|
||||
_shapeDisplay = shapeDisplay;
|
||||
_serializer = serializer;
|
||||
_staticHttpContextScopeFactory = staticHttpContextScopeFactory;
|
||||
_aliasService = aliasService;
|
||||
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
OnPublished<LayoutPart>(UpdateTemplateClients);
|
||||
@@ -77,6 +84,12 @@ namespace Orchard.Layouts.Handlers {
|
||||
draft.LayoutData = _serializer.Serialize(updatedLayout);
|
||||
|
||||
if (isPublished) {
|
||||
// If the content being published is currently the homepage, we need to change the DisplayAlias from "" to "/"
|
||||
// so that the autoroute part handler will not regenerate the alias and causes the homepage to become "lost".
|
||||
if (IsHomePage(layout)) {
|
||||
PromoteToHomePage(draft);
|
||||
}
|
||||
|
||||
// We don't have to recurse here, since invoking Publish on a Layout will cause this handler to execute again.
|
||||
_contentManager.Publish(draft.ContentItem);
|
||||
}
|
||||
@@ -85,5 +98,20 @@ namespace Orchard.Layouts.Handlers {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsHomePage(IContent content) {
|
||||
var homepage = _aliasService.Get(String.Empty);
|
||||
var displayRouteValues = _contentManager.GetItemMetadata(content).DisplayRouteValues;
|
||||
return homepage.Match(displayRouteValues);
|
||||
}
|
||||
|
||||
private void PromoteToHomePage(IContent content) {
|
||||
var autoroutePart = content.As<AutoroutePart>();
|
||||
|
||||
if (autoroutePart == null)
|
||||
return;
|
||||
|
||||
autoroutePart.DisplayAlias = "/";
|
||||
}
|
||||
}
|
||||
}
|
@@ -287,6 +287,14 @@
|
||||
<Project>{3158c928-888c-4a84-8bc1-4a8257489538}</Project>
|
||||
<Name>Markdown</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Alias\Orchard.Alias.csproj">
|
||||
<Project>{475b6c45-b27c-438b-8966-908b9d6d1077}</Project>
|
||||
<Name>Orchard.Alias</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Autoroute\Orchard.Autoroute.csproj">
|
||||
<Project>{66fccd76-2761-47e3-8d11-b45d0001ddaa}</Project>
|
||||
<Name>Orchard.Autoroute</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Forms\Orchard.Forms.csproj">
|
||||
<Project>{642a49d7-8752-4177-80d6-bfbbcfad3de0}</Project>
|
||||
<Name>Orchard.Forms</Name>
|
||||
|
Reference in New Issue
Block a user