-1

I wanna create an article as content part for a content type in migration of my module, but when I added the article, code show me an error. here's the code:

public int UpdateFrom3() {
            ContentDefinitionManager.AlterPartDefinition(typeof(TourPart).Name, cfg => cfg.Attachable());
            ContentDefinitionService.AddPartToType("Article" + "Part", "Tour");
            ContentDefinitionManager.AlterPartDefinition(
                   "Article" + "Part",
                   b => b
                .WithField("Name", f => f
                     .OfType("InputField").WithDisplayName("Name"))
                .WithField("ImageField", f => f
                    .OfType("MediaLibraryPickerField").WithDisplayName("Images")
                    .WithSetting("MediaLibraryPickerField.Hint", "Images everywhere!").WithSetting("MediaLibraryPickerFieldSettings.Required", "False")
                    .WithSetting("MediaLibraryPickerFieldSettings.Multiple", "True"))
               .WithField("ShortDesc", f => f
                   .OfType("TextField").WithDisplayName("Short Description")
                   .WithSetting("TextFieldSettings.Flavor", "Html"))
               .WithField("LongDesc", f => f
                   .OfType("TextField").WithDisplayName("Long Description")
                   .WithSetting("TextFieldSettings.Flavor", "Html")));


            return 4;
        }

at the ContentDefinitionService.AddPartToType("Article" + "Part", "Tour"); section, code show me this: An object reference is required for non-static field what can I do to my code accept this?

  • Does this answer your question? [C# error: "An object reference is required for the non-static field, method, or property"](https://stackoverflow.com/questions/10264308/c-sharp-error-an-object-reference-is-required-for-the-non-static-field-method) – Daniel Mann Dec 05 '20 at 07:03
  • @DanielMann the error is the same, but I don't think this answer works for me. – mohammad97mha Dec 05 '20 at 07:11
  • @DanielMann hey bro, I fixed it by my self. I should define my article in by ```.WithPart("Article")``` at first then use it this way: ```ContentDefinitionManager.AlterPartDefinition( "General", b => b .WithField("Name", f => f .OfType("InputField").WithDisplayName("Name")));``` – mohammad97mha Dec 05 '20 at 09:36
  • @DanielMann but still there is a problem. the index of search can't recognize content parts for searching. What's your solution؟؟؟ – mohammad97mha Dec 05 '20 at 09:41

1 Answers1

0

I find the answer by my self , Here's the solution:

public int UpdateFrom3()
        {
            ContentDefinitionManager.AlterPartDefinition(typeof(TourPart).Name, cfg => cfg.Attachable());

            ContentDefinitionManager.AlterTypeDefinition("Tour",
                cfg => cfg
                    .WithPart(typeof(TourPart).Name)
                    .WithPart("General")
                   );

            ContentDefinitionManager.AlterPartDefinition(
                   "General",
                   b => b
                .WithField("Name", f => f
                     .OfType("InputField").WithDisplayName("Name"))
                .WithField("NameManage", f => f
                     .OfType("InputField").WithDisplayName("NameManage"))
                .WithField("TourTypes", f => f
                     .OfType("InputField").WithDisplayName("TourTypes"))
                .WithField("TourTitle", f => f
                     .OfType("InputField").WithDisplayName("TourTitle"))
                .WithField("TourSubTitle", f => f
                     .OfType("InputField").WithDisplayName("TourSubTitle"))
                .WithField("TourSummary", f => f
                     .OfType("InputField").WithDisplayName("TourSummary"))

               .WithField("AboutTour", f => f
                   .OfType("TextField").WithDisplayName("AboutTour")
                   .WithSetting("TextFieldSettings.Flavor", "Html"))
               .WithField("Duration", f => f
                     .OfType("InputField").WithDisplayName("Duration"))

               .WithField("Cities", f => f
                   .OfType("TextField").WithDisplayName("Cities")
                   .WithSetting("TextFieldSettings.Flavor", "Html"))
               .WithField("TourIncludes", f => f
                   .OfType("TextField").WithDisplayName("TourIncludes")
                   .WithSetting("TextFieldSettings.Flavor", "Html"))
               .WithField("TourDestination", f => f
                     .OfType("InputField").WithDisplayName("TourDestination")));


            return 4;
        }