mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#19084: Handling publishing/unpublishing event for Content Menu Items
When a content item is removed, its menu items are also. When a content item is unpublished, its menu items are also. When a content item is published, its menu items are also. Work Item: 19084 --HG-- branch : 1.x
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
using JetBrains.Annotations;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Core.Navigation.Models;
|
||||||
|
using Orchard.Data;
|
||||||
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Navigation.Handlers {
|
||||||
|
[UsedImplicitly]
|
||||||
|
public class NavigationPartHandler : ContentHandler {
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
private readonly IRepository<ContentMenuItemPartRecord> _repository;
|
||||||
|
|
||||||
|
public NavigationPartHandler(IContentManager contentManager, IRepository<ContentMenuItemPartRecord> repository) {
|
||||||
|
_contentManager = contentManager;
|
||||||
|
_repository = repository;
|
||||||
|
|
||||||
|
OnRemoving<NavigationPart>((context, part) => RemoveContentItems(part));
|
||||||
|
|
||||||
|
OnUnpublished<NavigationPart>((context, part) => UnpublishContentItems(part));
|
||||||
|
OnPublished<NavigationPart>((context, part) => PublishContentItems(part));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveContentItems(NavigationPart part) {
|
||||||
|
// look for ContentMenuItemPart with this content
|
||||||
|
var contentMenuItemRecords = _repository.Fetch(x => x.ContentMenuItemRecord == part.ContentItem.Record);
|
||||||
|
|
||||||
|
// delete all menu items linking to this content item
|
||||||
|
foreach (var contentMenuItemRecord in contentMenuItemRecords) {
|
||||||
|
// look for any version
|
||||||
|
var contentItem = _contentManager.Get(contentMenuItemRecord.Id, VersionOptions.AllVersions);
|
||||||
|
if (contentItem != null) {
|
||||||
|
_contentManager.Remove(contentItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnpublishContentItems(NavigationPart part) {
|
||||||
|
// look for ContentMenuItemPart with this content
|
||||||
|
var contentMenuItemRecords = _repository.Fetch(x => x.ContentMenuItemRecord == part.ContentItem.Record);
|
||||||
|
|
||||||
|
// delete all menu items linking to this content item
|
||||||
|
foreach (var contentMenuItemRecord in contentMenuItemRecords) {
|
||||||
|
// look for a published version only
|
||||||
|
var contentItem = _contentManager.Get(contentMenuItemRecord.Id);
|
||||||
|
if (contentItem != null) {
|
||||||
|
_contentManager.Unpublish(contentItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PublishContentItems(NavigationPart part) {
|
||||||
|
// look for ContentMenuItemPart with this content
|
||||||
|
var contentMenuItemRecords = _repository.Fetch(x => x.ContentMenuItemRecord == part.ContentItem.Record);
|
||||||
|
|
||||||
|
// delete all menu items linking to this content item
|
||||||
|
foreach (var contentMenuItemRecord in contentMenuItemRecords) {
|
||||||
|
// even look for an unpublished version
|
||||||
|
var contentItem = _contentManager.Get(contentMenuItemRecord.Id, VersionOptions.Latest);
|
||||||
|
if(contentItem != null) {
|
||||||
|
_contentManager.Publish(contentItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -21,6 +21,10 @@
|
|||||||
</UpgradeBackupLocation>
|
</UpgradeBackupLocation>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
<UseIISExpress>false</UseIISExpress>
|
<UseIISExpress>false</UseIISExpress>
|
||||||
|
<IISExpressSSLPort />
|
||||||
|
<IISExpressAnonymousAuthentication />
|
||||||
|
<IISExpressWindowsAuthentication />
|
||||||
|
<IISExpressUseClassicPipelineMode />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@@ -138,6 +142,7 @@
|
|||||||
<Compile Include="Navigation\Drivers\MenuWidgetPartDriver.cs" />
|
<Compile Include="Navigation\Drivers\MenuWidgetPartDriver.cs" />
|
||||||
<Compile Include="Navigation\Handlers\AdminMenuPartHandler.cs" />
|
<Compile Include="Navigation\Handlers\AdminMenuPartHandler.cs" />
|
||||||
<Compile Include="Navigation\Handlers\ContentMenuItemPartHandler.cs" />
|
<Compile Include="Navigation\Handlers\ContentMenuItemPartHandler.cs" />
|
||||||
|
<Compile Include="Navigation\Handlers\NavigationPartHandler.cs" />
|
||||||
<Compile Include="Navigation\Handlers\MenuHandler.cs" />
|
<Compile Include="Navigation\Handlers\MenuHandler.cs" />
|
||||||
<Compile Include="Navigation\Handlers\MenuWidgetPartHandler.cs" />
|
<Compile Include="Navigation\Handlers\MenuWidgetPartHandler.cs" />
|
||||||
<Compile Include="Navigation\Models\AdminMenuPart.cs" />
|
<Compile Include="Navigation\Models\AdminMenuPart.cs" />
|
||||||
|
Reference in New Issue
Block a user