Adding widget to existing module

Topics: Writing modules
Jul 19, 2012 at 2:30 PM

So i wrote a module without widgets. Now that i want to add widgets there seems to be a problem. Not sure if you just can't add widgets later on, or if i'm missing something.

I tried following http://www.deepcode.co.uk/2011/05/real-world-orchard-cms-part-3-creating.html

The widget needs to load data from an existing service. It doesn't require an adittion record in the database

Added to my existing module.txt

 

Features:
    NopComCartWidget:
        Name: Cart for NopCommerce
        Category: Commerce
        Description: Widget for show cart items and link to cart

 

Wrote this in migrations.cs

[OrchardFeature("NopComCartWidget")]
    public class Migrations : DataMigrationImpl
    {
        public int Create()
        {
            ContentDefinitionManager.AlterPartDefinition(typeof(NopComCartWidgetPart).Name,
                builder => builder.Attachable());
           

            return 1;
        }

        public int UpdateFrom1()
        {
            // Tell the content def manager that we have a content type called TwitterWidget
            // the parts it contains and that it should be treated as a widget
            ContentDefinitionManager.AlterTypeDefinition("NopComCartWidget",
                cfg => cfg
                    .WithPart("NopComCartWidgetPart")
                    .WithPart("WidgetPart")
                    .WithPart("CommonPart")
                    .WithSetting("Stereotype", "Widget"));
            return 2;
        }

I added a file called Placement.info

<Placement>
  <Place Parts_NopComCartWidget="Content:1"/>
  <Place Parts_NopComCartWidget_Edit="Content:7.5"/>
</Placement>

And wrote the needed driver, view and widgetpart.


When i now run the orchard project, the debug doesn't seem to break on the Create() methode of migrations.cs. Since their never where any widgets, I presume it should have broken. Nor does the widget show up on the content page.
Judging from the table Settings_ContentTypeDefinitionRecord it hasn't been added to the system either.

I've read about people having success after restarting their IIS. Or when they changed the number value of UpdateFromX().

Anyone who has an idea of what i'm still missing?

Coordinator
Jul 23, 2012 at 11:34 AM

This just means that your migration already ran. Each step of migrations runs exactly once successfully. Unless you go into the database and hack the migration records, or you reset your database. Or you can write another step.