0
votes

I've a problem with orchard. I've created a widget that is a video player, it's a simple widget with the class ContentPartRecord:

public class VideoPlayerPartRecord : ContentPartRecord
    {
        public virtual string MediaFile { get; set; }
        public virtual int Width { get; set; }
        public virtual int Height { get; set; }
        public virtual bool AutoStart { get; set; }
        public virtual bool Repeat { get; set; }
    }

and the class ContentPart:

    public class VideoPlayerPart : ContentPart<VideoPlayerPartRecord>
        {
            [Required(ErrorMessage = "Media File required")]
            [Display(Name = "Media File: ")]
            public string MediaFile
            {
                get { return Record.MediaFile; }
                set { Record.MediaFile = value; }
            }

            [Required(ErrorMessage = "Width required")]
            [Display(Name = "Width: ")]
            public int Width
            {
                get { return Record.Width; }
                set { Record.Width = value; }
            }

            [Required(ErrorMessage = "Height required")]
            [Display(Name = "Height: ")]
            public int Height
            {
                get { return Record.Height; }
                set { Record.Height = value; }
            }

            [Display(Name = "Auto Start: ")]
            public bool AutoStart
            {
                get { return Record.AutoStart; }
                set { Record.AutoStart = value; }
            }

            [Display(Name = "Repeat: ")]
            public bool Repeat
            {
                get { return Record.Repeat; }
                set { Record.Repeat = value; }
            }
        }

this is the file migration:

    public class Migrations : DataMigrationImpl {

            public int Create() {
                // Creating table default_Raise_VideoPlayer_VideoPlayePartRecord
                SchemaBuilder.CreateTable("default_Raise_VideoPlayer_VideoPlayePartRecord", table => table
                    .ContentPartRecord()
                    .Column("MediaFile", DbType.String)
                    .Column("Width", DbType.Int32)
                    .Column("Height", DbType.Int32)
                    .Column("AutoStart", DbType.Boolean)
                    .Column("Repeat", DbType.Boolean)
                );

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

                return 1;
            }

            public int UpdateFrom1() {
                ContentDefinitionManager.AlterTypeDefinition("VideoPlayerWidget", cfg => cfg
                    .WithPart("VideoPlayerPart")
                    .WithPart("WidgetPart")
                    .WithPart("CommonPart")
                    .WithSetting("Stereotype", "Widget"));

                return 2;

            }


        }

the problem is that when I insert the widget it is added but I can't see it. Why??

1
Have you also created a handler and a driver class for your content part?mdm

1 Answers

1
votes

You need to add a Handler for your widget to persist the item, and a placement.info entry to present it.

http://docs.orchardproject.net/Documentation/Writing-a-content-part

(code taken from article)

using Maps.Models;
using Orchard.ContentManagement.Handlers;
using Orchard.Data;

namespace Maps.Handlers {
    public class MapHandler : ContentHandler {
        public MapHandler(IRepository<MapRecord> repository) {
            Filters.Add(StorageFilter.For(repository));
        }
    }
}

and Placement.info

<Placement>
    <Place Parts_Map="Content:10"/>
    <Place Parts_Map_Edit="Content:7.5"/>
</Placement>

If it doesn't save into a database - its probably the handler. If it doesn't display on screen, it's probably placement.info

Also you didn't mention having a driver or a view, but I'd guess it is the Handler or the placement info you are missing. Also, check spelling and convention very carefully when relating the driver, migration and placement info, as there are several places you can use the wrong text string if you create your parts manually.