0

我创建了一个自定义类型的项目,它有 4 个图像,我希望使用 4 个类型的媒体选择器,我已经添加了链接,所以......

public int Create()
            {
                // Define the project type 
                ContentDefinitionManager.AlterTypeDefinition("Project", cfg => cfg
                    .WithSetting("Stereotype", "Content")
                    .CommomPart()
                    .AutoroutePart("our-work")
                    .BodyPart()
                    .WithPart("TitlePart")
                    .WithPart("PublishLaterPart")
                    .WithPart("MenuPart", builder => builder
                        .WithSetting("MenuPart.OnMenu", "true")
                        .WithSetting("MenuPart.CurrentMenu", "Project Menu"))
                    .WithPart("Project")
                    .Creatable()
                    .Draftable());

                return 1;

            }

            public int UpdateFrom1()
            {
                // Define project part - having a part with the same name will create fields in the project type
                ContentDefinitionManager.AlterPartDefinition("Project", builder => builder
                   .MediaPickerField("MainImage")
                   .MediaPickerField("MediumImage")
                   .MediaPickerField("SmallImage")
                   .MediaPickerField("Logo")
                   .TextField("ShortDescription", Flavour.TextArea)
                   .TextField("Features", Flavour.Markdown)
                   .TextField("ClientTitle", Flavour.DefaultFlavour)
                   .TextField("ClientName", Flavour.DefaultFlavour)
                   .TextField("ClientQuote", Flavour.Textarea)
                   .BooleanField("MainProjectOnHomePage", false)
                   .Attachable());

                return 2;
            }

用于使其不那么冗长的扩展方法

public static ContentPartDefinitionBuilder MediaPickerField(this ContentPartDefinitionBuilder builder, 
                                                                string name, bool required = true, string hint = "")
    {
        var displayName = SplitCamel(name);

        // default implementation of Media picker field - create overloads for more options
        return  builder.WithField(name, fieldBuilder => fieldBuilder
                    .OfType("MediaPickerField")
                    .WithDisplayName(displayName)
                    .WithSetting("MediaPickerFieldSettings.Required", required.ToString(CultureInfo.InvariantCulture))
                    .WithSetting("MediaPickerFieldSettings.AllowedExtensions", "jpg png gif")
                    .WithSetting("MediaPickerFieldSettings.Hint", hint));

    }

    public static ContentPartDefinitionBuilder TextField(this ContentPartDefinitionBuilder builder, 
                                                         string name, Flavour flavor, bool required = true, string hint = "")
    {
        var strFlavor = SplitCamel(flavor.ToString());

        // default implementation of Media picker field - create overloads for more options
        return builder.WithField(name, fieldBuilder => fieldBuilder
                    .OfType("TextField")
                    .WithSetting("TextFieldSettings.Required", required.ToString(CultureInfo.InvariantCulture))
                    .WithSetting("TextFieldSettings.Flavor", strFlavor)
                    .WithSetting("TextFieldSettings.Hint", hint));

    }

我可以将媒体添加到仪表板中的 4 个字段,但在保存时只保存第一个媒体项,我可以保存项目,即使所有媒体字段都是必需的,但缺少 3 个字段的媒体项,

我还尝试通过仪表板添加一个额外的媒体选择器,结果相似。

难道我做错了什么?

4

0 回答 0