Search code examples
orchardcms

How do you delete or rename content parts in Orchard?


I gave a content part a wrong name and I want to rename it. I tried renaming the classes and all calls of it in the solution to no avail. I even tried deleting entries from the ShellFeatures table and the table generated by Migrations itself, but that just made things worse. Now the whole module's features aren't being recognized. Anyone tried this before?


Solution

  • I know this is an old question but I just had to tackle this and this is the first result I landed on from Google.

    You can delete the ContentPart and add it again using migrations for example:

        public int UpdateFrom3() {
            // remove the AccreditationsPart part cleanly
            ContentDefinitionManager.DeletePartDefinition(typeof (AccreditationsPart).Name);
    enter code here
            // re-add the AccreditationsPart again
            ContentDefinitionManager.AlterPartDefinition(typeof (AccreditationsPart).Name,
                cfg = > cfg
                .Attachable()
                .WithDescription("Adds a row of configurable accreditations to the content type"));
            return 4;
        }
    

    You would need to customise the update numbers to fit your current migrations.cs and also change the AlterPartDefinition to match whatever you want it to be.

    WARNING: This is only intended for fixing problems that you catch straight away. When you delete the part in the first section of the migration you will lose any associated data. If you already have the code running in production then you will have to use a different approach.