Custom ContentPart Driver not working

Topics: Customizing Orchard, Writing modules
Jun 26, 2014 at 1:44 PM
I have a custom content part and content part record I've created:
public class EventPartRecord : ContentPartRecord
    {
        public virtual string Presenter { get; set; }
        public virtual string PresenterURL { get; set; }
    }

    public class EventPart : ContentPart<EventPartRecord>
    {
        public string Presenter
        {
            get { return Record.Presenter; }
            set { Record.Presenter = value; }
        }

        public string PresenterURL
        {
            get { return Record.PresenterURL; }
            set { Record.PresenterURL = value; }
        }
    }
I'll eventually modify to make sure it uses an Infoset as well.

I've created it with a migration as a part and added it to a ContentType:
public int Create() {
            SchemaBuilder.CreateTable("Event", table => table
                .ContentPartRecord()
                .Column("Presenter", DbType.String)
                .Column("PresenterURL", DbType.String)
            );

            ContentDefinitionManager.AlterPartDefinition(
                typeof(EventPart).Name, cfg => cfg.Attachable());

            ContentDefinitionManager.AlterTypeDefinition("Event",
                cfg => cfg
                .WithPart("Event")
                .Creatable());

            return 1;
I've created a driver in order to edit the fields in the part when I create a Content Item from the ContentType:
namespace Events.Drivers
{
    public class EventPartDriver : ContentPartDriver<EventPart>
    {
        protected override string Prefix
        {
            get
            {
                return "My.Events";
            }
        }
        
        protected override DriverResult Editor(EventPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_Event_Edit",
                () => shapeHelper.EditorTemplate(
                        TemplateName: "Parts/Event",
                        Model: part,
                        Prefix: Prefix
                    ));
        }
    }
}
And I've added it to placement.info:
<Placement>
  <Place Parts_Event_Edit="Content:0" />
</Placement>
But when I create a content item, my editor shape template doesn't get rendered. I've got a view in the same module at at:
Views\EditorTemplates\Parts\Event.cshtml

It creates my table, creates my part, and creates my type. I create a new content item of my content type Event and nothing is present other than a save button.

I've set a breakpoint on the Driver's Editor override and it never fires. I'm missing something but I can't seem to figure it out. Any guidance?
Jun 26, 2014 at 3:31 PM
I figured it out.

The reason the Editor override in the driver wasn't being called is because the Part wasn't included in my Content Type. Changing the migration code AlterTypeDefinition to this would have done the trick:
public int Create() {
            SchemaBuilder.CreateTable("Event", table => table
                .ContentPartRecord()
                .Column("Presenter", DbType.String)
                .Column("PresenterURL", DbType.String)
            );

            ContentDefinitionManager.AlterPartDefinition(
                typeof(EventPart).Name, cfg => cfg.Attachable());

            ContentDefinitionManager.AlterTypeDefinition("Event",
                cfg => cfg
                .WithPart(typeof(EventPart).Name)
                .Creatable());

            return 1;
        }
This resolves the correct part name and everything works like a charm.