Orchard CMS 1.7 - 扩展媒体内容类型以获得标记类型功能

时间:2014-03-27 06:47:30

标签: orchardcms-1.7 orchard-modules

问题:

我的情况是我必须用geoID标记媒体项目。我一直在尝试复制Tags Module的功能主义者,并为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 Tags Models的精确复制。事实上,以上所有文件都是这样的。

我无法让地理对象编辑视图显示在图像(媒体)编辑视图中。

我需要帮助!

1 个答案:

答案 0 :(得分:1)

我得到了代码。

原来我必须将Driver和Handler类声明为public

几个月前我刚刚从PHP切换到ASP.NET,所以如果我们没有声明任何范围PHP会将其视为公开,我认为它与ASP.NET相同。

除此之外,代码本身没有其他问题。