orchardcmsorchardcms-1.7

How can I set the custom path of an AutoroutePart programmatically in a migration in Orchard?


In my Migrations.cs file I'm attaching an AutoroutePart to a Content Item.

ContentDefinitionManager.AlterTypeDefinition("Faq", type => type
    .WithPart("AutoroutePart")    
);

How can I tell the AutoroutePart to use some arbitrary string + the Content Item's slug as the custom path? I know I can change the settings of fields using .WithSetting("FieldSettings.Setting","Value") but this doesn't seem to be an option for Parts. I also wouldn't know how to refer to the SlugToken in code.


Solution

  • Should be possible

    ContentDefinitionManager.AlterTypeDefinition("Faq", type => type
    .WithPart("AutoroutePart", part => part
        .WithSetting("AutorouteSettings.AllowCustomPattern", "True")
        .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
        .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-faq\"}]")
        .WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))));