1
votes

I am building a custom module in Orchard 1.4 following Kevin Kuebler's Pluralsight tutorial. I believe I have everything in place that I need, but when I enable my module and attempt to add a new Article (My custom content type) I am not seeing the fields for my Custom Content Part. I have rebuilt from scratch numerous times following along with the tutorial, but keep getting stuck in this same spot. I have googled for answers, but from what I am seeing I have everything in place that I need. Below are pieces of my code.

Migrations.cs

using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
using Orchard.ContentManagement.MetaData;

    namespace Northern.Articles {
    public class Migrations : DataMigrationImpl {

        public int Create() {

            ContentDefinitionManager.AlterTypeDefinition("Article", builder =>
                builder.WithPart("CommonPart")
                .WithPart("TitlePart")
                .WithPart("AutoroutePart")
                .WithPart("BodyPart", partBuilder =>
                    partBuilder.WithSetting("BodyTypePartSettings.Flavor","Text")
                    )
                .Creatable()
                .Draftable()
                );

            return 1;
        }

        public int UpdateFrom1() {

            SchemaBuilder.CreateTable("ArticlePartRecord", table =>
                table.ContentPartRecord()
                .Column<int>("ArticleID")
                .Column<string>("PrimaryImage", col => col.WithLength(300))
                .Column<string>("ThumbImage", col => col.WithLength(300))
                .Column<bool>("IsFeatured"));

            ContentDefinitionManager.AlterTypeDefinition("Article", builder =>
                builder.WithPart("ArticlePart"));

            return 2;
        }
    }
}

ArticlePartRecord.cs

using Orchard.ContentManagement.Records;
namespace Northern.Articles.Models
{
    public class ArticlePartRecord : ContentPartRecord
    {
        public virtual int ArticleID { get; set; }
        public virtual string PrimaryImage { get; set; }
        public virtual string ThumbImage { get; set; }        
        public virtual bool IsFeatured { get; set; }
    }
}

ArticlePart.cs

using Orchard.ContentManagement;

namespace Northern.Articles.Models
{
    public class ArticlePart : ContentPart<ArticlePartRecord>
    {
        public int ArticleID {
            get { return Record.ArticleID; }
            set { Record.ArticleID = value; }
        }
        public string PrimaryImage
        {
            get { return Record.PrimaryImage; }
            set { Record.PrimaryImage = value; }
        }
        public string ThumbImage
        {
            get { return Record.ThumbImage; }
            set { Record.ThumbImage = value; }
        }
        public bool IsFeatured
        {
            get { return Record.IsFeatured; }
            set { Record.IsFeatured = value; }
        }
    }
}

ArticlePartDriver.cs

using Orchard.ContentManagement.Drivers;
using Northern.Articles.Models;
using Orchard.ContentManagement;

namespace Northern.Articles.Drivers
{
    class ArticlePartDriver : ContentPartDriver<ArticlePart>
    {
        protected override string Prefix
        {
            get
            {
                return "Article";
            }
        }

        //GET
        protected override DriverResult Editor(ArticlePart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_Article_Edit", () =>
                shapeHelper.EditorTemplate(TemplateName: "Parts/Article", Model: part, Prefix: Prefix));
        }

        // POST
        protected override DriverResult Editor(ArticlePart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}

ArticleHandler.cs

using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Northern.Articles.Models;

namespace Northern.Articles.Handler
{
    public class ArticleHandler : ContentHandler
    {
        public ArticleHandler(IRepository<ArticlePartRecord> articlePartRepository)
        {
            Filters.Add(StorageFilter.For(articlePartRepository));
        }
    }
}

Views\EditorTemplates\Parts\Article.cshtml

@model Northern.Articles.Models.ArticlePart

<fieldset>
    <legend>@T("Article Details")</legend>
    @Html.LabelFor(m => m.ArticleID, T("Article ID"))
    @Html.TextBoxFor(m => m.ArticleID)
    @Html.LabelFor(m => m.PrimaryImage, T("Primary Image"))
    @Html.TextBoxFor(m => m.PrimaryImage)
    @Html.LabelFor(m => m.ThumbImage, T("Thumbnail Image"))
    @Html.TextBoxFor(m => m.ThumbImage)
    @Html.LabelFor(m => m.IsFeatured, T("Is Featured"))
    @Html.CheckBoxFor(m => m.IsFeatured);
</fieldset> 

Placement.info

<?xml version="1.0" encoding="utf-8" ?>
<Placement>
  <Place Parts_Article_Edit="Content:10"/>
</Placement>

The module loads up correctly and the table is created in the DB, I am just not seeing the fields when i add/edit an Article.

Any help seeing what I cannot see would be appreciated.

1
Nothing seems obviously wrong to me. Next step would probably be to set-up breakpoints, in the driver for example, and see if they get hit.Bertrand Le Roy

1 Answers

1
votes

It looks to me like you have everything in place. The one thing I noticed looking at the code is that you don't have the public access modifier on the ArticlePartDriver class. Classes are internal by default in C# if you don't specify them as public. My guess is that Orchard isn't able to create the Driver class because it's not public.