mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-27 12:29:04 +08:00
MediaLibrary: Fixing that removing TitlePart from a type with MediaPart causes the type to be unusable due to an implicit dependency, fixes #6047
This commit is contained in:
@@ -1,25 +1,40 @@
|
|||||||
using System;
|
using System;
|
||||||
using Orchard.ContentManagement.Handlers;
|
|
||||||
using Orchard.Data;
|
|
||||||
using Orchard.MediaLibrary.Services;
|
|
||||||
using Orchard.MediaLibrary.Models;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Orchard.FileSystems.Media;
|
using System.Linq;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
|
using Orchard.Core.Title.Models;
|
||||||
|
using Orchard.Data;
|
||||||
|
using Orchard.FileSystems.Media;
|
||||||
|
using Orchard.MediaLibrary.Models;
|
||||||
|
using Orchard.MediaLibrary.Services;
|
||||||
|
|
||||||
namespace Orchard.MediaLibrary.Handlers {
|
namespace Orchard.MediaLibrary.Handlers {
|
||||||
public class MediaPartHandler : ContentHandler {
|
public class MediaPartHandler : ContentHandler {
|
||||||
private readonly IMediaLibraryService _mediaLibraryService;
|
private readonly IMediaLibraryService _mediaLibraryService;
|
||||||
private readonly IStorageProvider _storageProvider;
|
private readonly IStorageProvider _storageProvider;
|
||||||
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
|
|
||||||
public MediaPartHandler(
|
public MediaPartHandler(
|
||||||
IStorageProvider storageProvider,
|
IStorageProvider storageProvider,
|
||||||
IMediaLibraryService mediaLibraryService,
|
IMediaLibraryService mediaLibraryService,
|
||||||
IRepository<MediaPartRecord> repository) {
|
IRepository<MediaPartRecord> repository,
|
||||||
|
IContentDefinitionManager contentDefinitionManager) {
|
||||||
_storageProvider = storageProvider;
|
_storageProvider = storageProvider;
|
||||||
_mediaLibraryService = mediaLibraryService;
|
_mediaLibraryService = mediaLibraryService;
|
||||||
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
|
|
||||||
Filters.Add(StorageFilter.For(repository));
|
Filters.Add(StorageFilter.For(repository));
|
||||||
|
Filters.Add(new ActivatingFilter<TitlePart>(contentType => {
|
||||||
|
var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentType);
|
||||||
|
// To avoid NRE when the handler runs for ad-hoc content types, e.g. MediaLibraryExplorer.
|
||||||
|
return typeDefinition == null ?
|
||||||
|
false :
|
||||||
|
typeDefinition.Parts.Any(contentTypePartDefinition =>
|
||||||
|
contentTypePartDefinition.PartDefinition.Name == typeof(MediaPart).Name);
|
||||||
|
}));
|
||||||
|
|
||||||
OnRemoving<MediaPart>((context, part) => RemoveMedia(part));
|
OnRemoving<MediaPart>((context, part) => RemoveMedia(part));
|
||||||
OnLoaded<MediaPart>((context, part) => {
|
OnLoaded<MediaPart>((context, part) => {
|
||||||
if (!String.IsNullOrEmpty(part.FileName)) {
|
if (!String.IsNullOrEmpty(part.FileName)) {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
|
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
|
||||||
|
using Orchard.ContentManagement.Handlers;
|
||||||
using Orchard.ContentManagement.Utilities;
|
using Orchard.ContentManagement.Utilities;
|
||||||
using Orchard.Core.Title.Models;
|
using Orchard.Core.Title.Models;
|
||||||
|
using Orchard.MediaLibrary.Handlers;
|
||||||
|
|
||||||
namespace Orchard.MediaLibrary.Models {
|
namespace Orchard.MediaLibrary.Models {
|
||||||
public class MediaPart : ContentPart<MediaPartRecord> {
|
public class MediaPart : ContentPart<MediaPartRecord> {
|
||||||
@@ -11,6 +13,8 @@ namespace Orchard.MediaLibrary.Models {
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the title of the media.
|
/// Gets or sets the title of the media.
|
||||||
|
/// This adds an implicit dependency on <see cref="TitlePart"/> which will be resolved by an
|
||||||
|
/// <see cref="ActivatingFilter{TPart}"/> in the <see cref="MediaPartHandler"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Title {
|
public string Title {
|
||||||
get { return ContentItem.As<TitlePart>().Title; }
|
get { return ContentItem.As<TitlePart>().Title; }
|
||||||
@@ -63,7 +67,7 @@ namespace Orchard.MediaLibrary.Models {
|
|||||||
/// Gets the public Url of the media if stored locally.
|
/// Gets the public Url of the media if stored locally.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string MediaUrl {
|
public string MediaUrl {
|
||||||
get { return _publicUrl.Value; }
|
get { return _publicUrl.Value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user