2014-03-27 59 views
1

問題:果園CMS 1.7 - 擴展媒體內容類型,以獲取標記類型的功能

我有情況我有標記與大地水準面的媒體項目。我一直在試圖複製標籤模塊的功能,併爲GeoObject創建模型,視圖,驅動器和處理程序。我的問題是,當我加載圖像的編輯視圖時,我沒有得到我的GeoObject編輯視圖。

這裏是我的處理程序:

class GeoObjectsPartHandler:ContentHandler { 
    public GeoObjectsPartHandler(IRepository<GeoObjectsPartRecord> repository, IGeoObjectService geoObjectService) 
    { 
     Filters.Add(StorageFilter.For(repository)); 

     OnIndexing<GeoObjectsPart>(
      (context, geoObjectsPart) => 
      { 
       foreach (var geoObject in geoObjectsPart.CurrentGeoObjects) 
       { 
        context.DocumentIndex.Add("geoObjects", geoObject.GeoObjectName).Analyze(); 
       } 
      }); 
    } 
} 

司機:

[UsedImplicitly] 
class GeoObjectsPartDriver: ContentPartDriver<GeoObjectsPart> 
{ 
    private static readonly char[] _disalowedChars = new[] { '<', '>', '*', '%', ':', '&', '\\', '"', '|' }; 
    private const string TemplateName = "Parts/GeoObjects"; 
    private readonly INotifier _notifier; 
    private readonly IGeoObjectService _geoObjectService; 

    public GeoObjectsPartDriver(IGeoObjectService geoObjectService, INotifier notifier) 
    { 
     _geoObjectService = geoObjectService; 
     _notifier = notifier; 
     T = NullLocalizer.Instance; 
    } 

    public Localizer T { get; set; } 

    protected override string Prefix 
    { 
     get { return "GeoObjects"; } 
    } 

    protected override DriverResult Editor(GeoObjectsPart part, dynamic shapeHelper) 
    { 
     return ContentShape("Parts_GeoObjects_Edit", 
       () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: BuildEditorViewModel(part), Prefix: Prefix)); 
    } 

    protected override DriverResult Editor(GeoObjectsPart part, IUpdateModel updater, dynamic shapeHelper) 
    { 
     var model = new EditGeoObjectsViewModel(); 
     return ContentShape("Parts_GeoObjects_Edit", 
       () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)); 

    } 

    private static EditGeoObjectsViewModel BuildEditorViewModel(GeoObjectsPart part) 
    { 
     return new EditGeoObjectsViewModel 
     { 
      GeoObjects = string.Join(", ", part.CurrentGeoObjects.Select((t, i) => t.GeoObjectName).ToArray()) 
     }; 
    } 

    protected override void Importing(GeoObjectsPart part, ImportContentContext context) 
    { 
     var geoObjectString = context.Attribute(part.PartDefinition.Name, "GeoObjects"); 
    } 

    protected override void Exporting(GeoObjectsPart part, ExportContentContext context) 
    { 
     context.Element(part.PartDefinition.Name).SetAttributeValue("GeoObjects", String.Join(",", part.CurrentGeoObjects.Select(t => t.GeoObjectName))); 
    } 
} 

遷移:

using Orchard.Data.Migration; 
using Orchard.ContentManagement.MetaData; 
using Orchard.Core.Contents.Extensions; 
namespace ePageo.TUI.MediaManager 
{ 
    public class MediaManagerDataMigration : DataMigrationImpl 
    { 
     public int Create() 
     { 
      SchemaBuilder.CreateTable("GeoObjectsPartRecord", 
       table => table 
        .ContentPartRecord() 
       ); 

      SchemaBuilder.CreateTable("GeoObjectRecord", 
       table => table 
        .Column<int>("Id", column => column.PrimaryKey().Identity()) 
        .Column<string>("GeoObjectName") 
       ); 

      SchemaBuilder.CreateTable("ContentGeoObjectRecord", 
       table => table 
        .Column<int>("Id", column => column.PrimaryKey().Identity()) 
        .Column<int>("GeoObjectRecord_Id") 
        .Column<int>("GeoObjectsPartRecord_Id") 
       ); 

      ContentDefinitionManager.AlterPartDefinition("GeoObjectsPart", builder => builder.Attachable()); 


      return 1; 
     } 

     public int UpdateFrom1() 
     { 
      ContentDefinitionManager.AlterPartDefinition("GeoObjectsPart", builder => builder 
       .WithDescription("Allows to add Geo-object ids to the particular media Item.")); 
      return 2; 
     } 

     public int UpdateFrom2() 
     { 
      ContentDefinitionManager.AlterTypeDefinition("Image", td => td 
       .WithPart("GeoObjectsPart") 
      ); 

      ContentDefinitionManager.AlterTypeDefinition("Video", td => td 
       .WithPart("GeoObjectsPart") 
      ); 

      ContentDefinitionManager.AlterTypeDefinition("Audio", td => td 
       .WithPart("GeoObjectsPart") 
      ); 

      ContentDefinitionManager.AlterTypeDefinition("Document", td => td 
       .WithPart("GeoObjectsPart") 
      ); 

      ContentDefinitionManager.AlterTypeDefinition("OEmbed", td => td 
       .WithPart("GeoObjectsPart") 
      ); 
      return 3; 
     } 

    } 
} 

Placement.info:

<Placement> 
    <Place Parts_GeoObjects_Edit="Content:12"/> 
</Placement> 

我認爲我的模型沒有問題,因爲它確實複製了Orchard標記模型。事實上,所有上述文件都是這樣。

我只是無法讓地理對象編輯視圖顯示在圖像(媒體)編輯視圖。

我需要幫助!

回答

1

我得到的代碼工作。

原來,我不得不將驅動程序和處理程序類聲明爲public

我剛剛從幾個月前從PHP切換到ASP.NET,因此,如果我們沒有聲明任何範圍PHP將它作爲公共,我認爲它將與ASP.NET一樣。

代碼本身沒有其他問題,除此之外。