示例#1
0
        public async Task <dynamic> UpdateTypeEditorAsync(ContentTypeDefinition contentTypeDefinition, IUpdateModel updater, string groupId)
        {
            if (contentTypeDefinition == null)
            {
                throw new ArgumentNullException(nameof(contentTypeDefinition));
            }

            dynamic contentTypeDefinitionShape = await CreateContentShapeAsync("ContentTypeDefinition_Edit");

            contentTypeDefinitionShape.ContentTypeDefinition = contentTypeDefinition;

            var layout = await _layoutAccessor.GetLayoutAsync();

            _contentDefinitionManager.AlterTypeDefinition(contentTypeDefinition.Name, typeBuilder =>
            {
                var typeContext = new UpdateTypeEditorContext(
                    typeBuilder,
                    contentTypeDefinitionShape,
                    groupId,
                    false,
                    _shapeFactory,
                    layout,
                    updater
                    );

                BindPlacementAsync(typeContext).GetAwaiter().GetResult();

                _handlers.InvokeAsync((handler, contentTypeDefinition, typeContext) => handler.UpdateTypeEditorAsync(contentTypeDefinition, typeContext), contentTypeDefinition, typeContext, Logger).GetAwaiter().GetResult();
            });

            return(contentTypeDefinitionShape);
        }
示例#2
0
        public Task <dynamic> UpdateTypeEditorAsync(ContentTypeDefinition contentTypeDefinition, IUpdateModel updater, string groupId)
        {
            if (contentTypeDefinition == null)
            {
                throw new ArgumentNullException(nameof(contentTypeDefinition));
            }

            dynamic contentTypeDefinitionShape = CreateContentShape("ContentTypeDefinition_Edit");

            contentTypeDefinitionShape.ContentTypeDefinition = contentTypeDefinition;

            _contentDefinitionManager.AlterTypeDefinition(contentTypeDefinition.Name, typeBuilder =>
            {
                var typeContext = new UpdateTypeEditorContext(
                    typeBuilder,
                    contentTypeDefinitionShape,
                    groupId,
                    _shapeFactory,
                    _layoutAccessor.GetLayout(),
                    updater
                    );

                BindPlacementAsync(typeContext).Wait();

                _handlers.InvokeAsync(handler => handler.UpdateTypeEditorAsync(contentTypeDefinition, typeContext), Logger).Wait();
            });

            return(Task.FromResult <dynamic>(contentTypeDefinitionShape));
        }
示例#3
0
        public int Create()
        {
            _contentDefinitionManager.AlterTypeDefinition("WorkMap", menu => menu
                                                          .Draftable()
                                                          .Versionable()
                                                          .Creatable()
                                                          .Listable()
                                                          .Enabled()
                                                          .WithPart("TitlePart", part => part.WithPosition("1"))
                                                          // .WithPart("AliasPart", part => part.WithPosition("2").WithSettings(new AliasPartSettings { Pattern = "{{ ContentItem | display_text | slugify }}" }))
                                                          .WithPart("WorkMapPart", part => part.WithPosition("3"))
                                                          );

//            SchemaBuilder.CreateMapIndexTable(nameof(TaxonomyIndex), table => table
//                .Column<string>("TaxonomyContentItemId", c => c.WithLength(26))
//                .Column<string>("ContentItemId", c => c.WithLength(26))
//                .Column<string>("ContentType", column => column.WithLength(255))
//                .Column<string>("ContentPart", column => column.WithLength(255))
//                .Column<string>("ContentField", column => column.WithLength(255))
//                .Column<string>("TermContentItemId", column => column.WithLength(26))
//            );
//
//            SchemaBuilder.AlterTable(nameof(TaxonomyIndex), table => table
//                .CreateIndex("IDX_TaxonomyIndex_List", "ContentType", "ContentPart", "ContentField")
//            );
//
//            SchemaBuilder.AlterTable(nameof(TaxonomyIndex), table => table
//                .CreateIndex("IDX_TaxonomyIndex_Search", "TermContentItemId")
//            );

            return(1);
        }
示例#4
0
        // This creates some useful type definitions for bag parts.
        public int UpdateFrom1()
        {
            _contentDefinitionManager.AlterTypeDefinition("Bar", type => type
                                                          .DisplayedAs("Bar")
                                                          .WithPart("HtmlBodyPart")
                                                          );

            _contentDefinitionManager.AlterTypeDefinition("Foo", type => type
                                                          .DisplayedAs("Foo")
                                                          .WithPart("MarkdownBodyPart")
                                                          );

            _contentDefinitionManager.AlterTypeDefinition("Bag", type => type
                                                          .DisplayedAs("Bag container")
                                                          .Listable()
                                                          .Creatable()
                                                          .Securable()
                                                          .Draftable()
                                                          .Versionable()
                                                          .WithPart("Items", "BagPart", part => part
                                                                    .WithDescription("Item bag")
                                                                    .WithSettings(new BagPartSettings
            {
                ContainedContentTypes = new string[] { "Bar", "Foo" }
            }
                                                                                  )
                                                                    ));

            return(2);
        }
示例#5
0
 public int Create()
 {
     _contentDefinitionManager.AlterPartDefinition("Page", p => p
                                                   .WithDisplayName("Page")
                                                   .WithHtmlField("UnauthorizedHtml", "Unauthorized Html", "Displayed when no redirect is provided and the user is not authorized", "0")
                                                   );
     _contentDefinitionManager.AlterTypeDefinition("Page", type => type
                                                   .DisplayedAs("Page")
                                                   .Creatable()
                                                   .Listable()
                                                   .Draftable()
                                                   .Versionable()
                                                   .Securable()
                                                   .WithPart("LocalizationPart", part => part
                                                             .WithPosition("0")
                                                             )
                                                   .WithPart("TitlePart", part => part
                                                             .WithPosition("1")
                                                             )
                                                   .WithPart("AutoroutePart", part => part
                                                             .WithPosition("2")
                                                             .WithSettings(new AutoroutePartSettings
     {
         AllowCustomPath    = true,
         Pattern            = "{{ ContentItem | display_text | slugify }}",
         ShowHomepageOption = true,
     })
                                                             )
                                                   .WithFlow("3")
                                                   .WithContentPermission("4")
                                                   .WithPart("Page", p => p.WithPosition("5"))
                                                   );
     return(2);
 }
示例#6
0
        public ContentTypeDefinition AddType(string name, string displayName)
        {
            if (String.IsNullOrWhiteSpace(displayName))
            {
                throw new ArgumentException(nameof(displayName));
            }

            if (String.IsNullOrWhiteSpace(name))
            {
                name = GenerateContentTypeNameFromDisplayName(displayName);
            }
            else
            {
                if (!name[0].IsLetter())
                {
                    throw new ArgumentException("Content type name must start with a letter", "name");
                }
            }

            while (_contentDefinitionManager.GetTypeDefinition(name) != null)
            {
                name = VersionName(name);
            }

            var contentTypeDefinition = new ContentTypeDefinition(name, displayName);

            _contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition);
            _contentDefinitionManager.AlterTypeDefinition(name, cfg => cfg.Creatable().Draftable().Listable().Securable());
            _eventBus.Notify <IContentDefinitionEventHandler>(x => x.ContentTypeCreated(new ContentTypeCreatedContext {
                ContentTypeDefinition = contentTypeDefinition
            }));

            return(contentTypeDefinition);
        }
示例#7
0
        public int Create()
        {
            //parts
            _contentDefinitionManager.AlterPartDefinition(nameof(ProjectionPart), builder => builder
                                                          .Attachable()
                                                          .WithDescription("Add a Projection behavior."));


            //contenttypes
            _contentDefinitionManager.AlterTypeDefinition("Projection", item => item
                                                          .DisplayedAs("Projection")
                                                          .Draftable()
                                                          .Creatable()
                                                          .Enabled()
                                                          .Listable()
                                                          .Securable()
                                                          .WithPart("TitlePart", part => part.WithPosition("0"))
                                                          .WithPart("Projection") //need to add dummy type part for fields to be attached
                                                                                  // .WithPart("ProjectionPart", part => part.WithPosition("1"))
                                                                                  // .WithPart("AliasPart", part => part.WithPosition("2").WithSettings(new OrchardCore.Alias.Settings.AliasPartSettings { Pattern = "{{slug}}" }))
                                                                                  // .WithPart("BodyPart", part => part.WithPosition("3").WithSettings(new OrchardCore.Body.Settings.BodyPartSettings { Editor = "Wysiwyg" }) )
                                                                                  //  .WithPart("ListPart", part => part.WithPosition("4").WithSettings(new OrchardCore.Lists.Models.ListPartSettings { ContainedContentTypes = new[] { "PolicyArea", "PolicySection" }, PageSize = 10 }))
                                                          .WithPart(nameof(ProjectionPart), part => part.WithPosition("1").WithSettings(new ProjectionPartSettings()
            {
                PageSize = 20
            }))
                                                          //  .WithPart("TreeBreadCrumbPart", part => part.WithPosition("5"))
                                                          );


            return(1);
        }
示例#8
0
        public int Create()
        {
            _contentDefinitionManager.AlterTypeDefinition("Taxonomy", taxonomy => taxonomy
                                                          .Draftable()
                                                          .Versionable()
                                                          .Creatable()
                                                          .Listable()
                                                          .WithPart("TitlePart", part => part.WithPosition("1"))
                                                          .WithPart("AliasPart", part => part
                                                                    .WithPosition("2")
                                                                    .WithSettings(new AliasPartSettings
            {
                Pattern = "{{ Model.ContentItem | display_text | slugify }}"
            }))
                                                          .WithPart("AutoroutePart", part => part
                                                                    .WithPosition("3")
                                                                    .WithSettings(new AutoroutePartSettings
            {
                Pattern = "{{ Model.ContentItem | display_text | slugify }}",
                AllowRouteContainedItems = true
            }))
                                                          .WithPart("TaxonomyPart", part => part.WithPosition("4"))
                                                          );

            SchemaBuilder.CreateMapIndexTable <TaxonomyIndex>(table => table
                                                              .Column <string>("TaxonomyContentItemId", c => c.WithLength(26))
                                                              .Column <string>("ContentItemId", c => c.WithLength(26))
                                                              .Column <string>("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize))
                                                              .Column <string>("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize))
                                                              .Column <string>("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize))
                                                              .Column <string>("TermContentItemId", column => column.WithLength(26))
                                                              .Column <bool>("Published", c => c.WithDefault(true))
                                                              .Column <bool>("Latest", c => c.WithDefault(false))
                                                              );

            SchemaBuilder.AlterIndexTable <TaxonomyIndex>(table => table
                                                          .CreateIndex("IDX_TaxonomyIndex_DocumentId",
                                                                       "DocumentId",
                                                                       "TaxonomyContentItemId",
                                                                       "ContentItemId",
                                                                       "TermContentItemId",
                                                                       "Published",
                                                                       "Latest")
                                                          );

            SchemaBuilder.AlterIndexTable <TaxonomyIndex>(table => table
                                                          .CreateIndex("IDX_TaxonomyIndex_DocumentId_ContentType",
                                                                       "DocumentId",
                                                                       "ContentType",
                                                                       "ContentPart",
                                                                       "ContentField",
                                                                       "Published",
                                                                       "Latest")
                                                          );

            // Shortcut other migration steps on new content definition schemas.
            return(5);
        }
示例#9
0
        public async Task <int> CreateAsync()
        {
            await _recipeMigrator.ExecuteAsync("types.recipe.json", this);

            await _recipeMigrator.ExecuteAsync("queries.recipe.json", this);

            await _recipeMigrator.ExecuteAsync("content.recipe.json", this);

            _contentDefinitionManager.AlterTypeDefinition("Taxonomy", t => t.Securable());
            return(3);
        }
示例#10
0
 private void Tabs()
 {
     _contentDefinitionManager.CreateBasicWidget("Tabs");
     _contentDefinitionManager.AlterTypeDefinition("Tabs", t => t
                                                   .WithTitlePart("0")
                                                   .WithFlow("1", new string[] { "Tab" })
                                                   );
     _contentDefinitionManager.CreateBasicWidget("Tab");
     _contentDefinitionManager.AlterTypeDefinition("Tab", t => t
                                                   .WithTitlePart("0", TitlePartOptions.EditableRequired)
                                                   .WithFlow("2")
                                                   );
 }
示例#11
0
        public JsonResult CreateTypeContents()
        {
            var temp = this.DeserializeObject <IEnumerable <NewPartVM> >();

            foreach (var item in temp)
            {
                ContentItem DevicesInfoContentItem = _contentManager.New("新闻组管理");
                DevicesInfoContentItem.Alter <NewPart>(x => x.NewDisplayName = item.NewDisplayName);
                DevicesInfoContentItem.Alter <NewPart>(x => x.NewDescription = item.NewDescription);
                DevicesInfoContentItem.Alter <NewPart>(x => x.Classify       = item.Classify);
                item.Name = "ContentType_" + item.NewDisplayName;
                if (_contentDefinitionManager.GetTypeDefinition(item.Name) == null)
                {
                    if (item.Classify == false)
                    {
                        var BodyPartSetting = new BodyPartSettings {
                        };
                        BodyPartSetting.Editor = "Wysiwyg";
                        _contentDefinitionService.AddType(item.Name, item.NewDisplayName);
                        _contentDefinitionManager.AlterTypeDefinition(item.Name, bulid => bulid
                                                                      .Draftable()
                                                                      .Creatable()
                                                                      .Listable()
                                                                      .WithPart("TitlePart")
                                                                      .WithPart("BodyPart", part => part.WithSettings(BodyPartSetting))
                                                                      );
                    }
                    else
                    {
                        var BodyPartSetting = new BodyPartSettings {
                        };
                        BodyPartSetting.Editor = "Wysiwyg";
                        _contentDefinitionManager.AlterTypeDefinition(item.Name, bulid => bulid
                                                                      .DisplayedAs(item.NewDisplayName)
                                                                      .Draftable()
                                                                      .Creatable()
                                                                      .Listable()
                                                                      .WithPart("TitlePart", part => part.WithPosition("2"))
                                                                      .WithPart("BodyPart", part => part.WithSettings(BodyPartSetting).WithPosition("3"))
                                                                      .WithPart("TypeNewClassifyPart", part => part.WithPosition("1"))
                                                                      );
                    }
                }
                DevicesInfoContentItem.Alter <TitlePart>(x => x.Title = item.NewDisplayName);
                DevicesInfoContentItem.Alter <NewPart>(x => x.Name    = item.Name);
                _contentDefinitionManager.GetTypeDefinition(item.Name);
                _contentManager.Create(DevicesInfoContentItem);
                item.NewID = DevicesInfoContentItem.ContentItemId;
            }
            return(this.Jsonp(temp));
        }
示例#12
0
        private void VTimeline()
        {
            _contentDefinitionManager.AlterTypeDefinition("VTimeline", type => type
                                                          .DisplayedAs("VTimeline")
                                                          .Stereotype("Widget")
                                                          .WithPart("VTimeline", part => part
                                                                    .WithPosition("0")
                                                                    )
                                                          .WithPart("FlowPart", part => part
                                                                    .WithSettings(new FlowPartSettings
            {
                ContainedContentTypes = new[] { "VTimelineItem" },
            })
                                                                    )
                                                          );

            _contentDefinitionManager.AlterPartDefinition("VTimeline", part => part
                                                          .WithField("Props", field => field
                                                                     .OfType("MultiTextField")
                                                                     .WithDisplayName("Props")
                                                                     .WithEditor("Picker")
                                                                     .WithPosition("0")
                                                                     .WithSettings(new MultiTextFieldSettings
            {
                Options = new MultiTextFieldValueOption[] {
                    new MultiTextFieldValueOption()
                    {
                        Name = "Align Top", Value = "align-top"
                    },
                    new MultiTextFieldValueOption()
                    {
                        Name = "Dark", Value = "dark"
                    },
                    new MultiTextFieldValueOption()
                    {
                        Name = "Dense", Value = "dense"
                    },
                    new MultiTextFieldValueOption()
                    {
                        Name = "Light", Value = "light"
                    },
                    new MultiTextFieldValueOption()
                    {
                        Name = "Reverse", Value = "reverse"
                    }
                },
            })
                                                                     )
                                                          );
        }
示例#13
0
        public int Create()
        {
            //parts
            _contentDefinitionManager.AlterPartDefinition(nameof(ProjectPart), builder => builder
                                                          .Attachable()
                                                          .WithDisplayName("Project Part")
                                                          .Reusable(false)
                                                          .WithDescription("Turns content type into a Project."));



            //content types
            //binder
            _contentDefinitionManager.AlterTypeDefinition("Project", item => item
                                                          .DisplayedAs("Project")
                                                          .Draftable()
                                                          .Creatable()
                                                          .Listable()
                                                          .Enabled()
                                                          .Securable(false)
                                                          .WithPart("Project")
                                                          .WithPart("TitlePart", part => part.WithPosition("0"))
                                                          .WithPart(nameof(ProjectPart), part => part.WithPosition("1"))

                                                          // .WithPart("ListPart", builder => builder.WithSetting("ContainedContentTypes", new[] { "WorkDocument", "SpreadSheet", "Presentation" }).WithSetting("PageSize", "20"))
                                                          );



            return(1);
        }
        public MarkdownSiteSettingsPartHandler(IContentDefinitionManager contentDefinitionManager) {
            _contentDefinitionManager = contentDefinitionManager;
            Filters.Add(new ActivatingFilter<MarkdownSiteSettingsPart>("Site"));
            Filters.Add(new TemplateFilterForPart<MarkdownSiteSettingsPart>("MarkdownSiteSettings", "Parts/Markdown.MarkdownSiteSettings", "markdown"));
            OnInitializing<MarkdownSiteSettingsPart>((context, part) => {
                part.UseMarkdownForBlogs = false;
            });

            OnUpdated<MarkdownSiteSettingsPart>((context, part) => {
                var blogPost = _contentDefinitionManager.GetTypeDefinition("BlogPost");
                if (blogPost == null) {
                        return;
                }

                var bodyPart = blogPost.Parts.FirstOrDefault(x => x.PartDefinition.Name == "BodyPart");
                if (bodyPart == null) {
                    return;
                }

                _contentDefinitionManager.AlterTypeDefinition("BlogPost", build => build
                    .WithPart("BodyPart", cfg => cfg
                        .WithSetting("BodyTypePartSettings.Flavor", part.UseMarkdownForBlogs ? "markdown" : "html")
                    )
                );
            });

            T = NullLocalizer.Instance;
        }
示例#15
0
    private void DefineContents(IEnumerable <ContentTypeDefinition> typeDefinitions,
                                IEnumerable <ContentPartDefinition> partDefinitions,
                                IEnumerable <ContentPartRegisterModel> contentPartRegisters)
    {
        foreach (var typeDefinition in typeDefinitions)
        {
            //define a content type with its content parts
            _contentDefinitionManager.AlterTypeDefinition(typeDefinition.Name, type =>
            {
                type.Draftable(typeDefinition.Draftable)
                .Versionable(typeDefinition.Versionable)
                .Creatable(typeDefinition.Creatable)
                .Securable(typeDefinition.Securable)
                .Listable(typeDefinition.Listable)
                .WithPart(typeDefinition.DefaultContentPart.Name);

                foreach (var register in contentPartRegisters)
                {
                    if (register.ContentType == typeDefinition.Name)
                    {
                        type.WithPart($"{register.ContentPart}Part");
                    }
                }

                DefineContentPart(typeDefinition.DefaultContentPart, true);
            });
        }

        //Define all content parts
        foreach (var partDefinition in partDefinitions)
        {
            DefineContentPart(partDefinition);
        }
    }
        public MarkdownSiteSettingsPartHandler(IContentDefinitionManager contentDefinitionManager)
        {
            _contentDefinitionManager = contentDefinitionManager;
            Filters.Add(new ActivatingFilter <MarkdownSiteSettingsPart>("Site"));
            Filters.Add(new TemplateFilterForPart <MarkdownSiteSettingsPart>("MarkdownSiteSettings", "Parts/Markdown.MarkdownSiteSettings", "markdown"));
            OnInitializing <MarkdownSiteSettingsPart>((context, part) => {
                part.UseMarkdownForBlogs = false;
            });

            OnUpdated <MarkdownSiteSettingsPart>((context, part) => {
                var blogPost = _contentDefinitionManager.GetTypeDefinition("BlogPost");
                if (blogPost == null)
                {
                    return;
                }

                var bodyPart = blogPost.Parts.FirstOrDefault(x => x.PartDefinition.Name == "BodyPart");
                if (bodyPart == null)
                {
                    return;
                }

                _contentDefinitionManager.AlterTypeDefinition("BlogPost", build => build
                                                              .WithPart("BodyPart", cfg => cfg
                                                                        .WithSetting("BodyTypePartSettings.Flavor", part.UseMarkdownForBlogs ? "markdown" : "html")
                                                                        )
                                                              );
            });

            T = NullLocalizer.Instance;
        }
示例#17
0
        public void CreatePattern(string contentType, string name, string pattern, string description, bool makeDefault)
        {
            var contentDefinition = _contentDefinitionManager.GetTypeDefinition(contentType);

            if (contentDefinition == null)
            {
                throw new OrchardException(T("Unknown content type: {0}", contentType));
            }

            var settings = contentDefinition.Settings.GetModel <AutorouteSettings>();

            var routePattern = new RoutePattern {
                Description = description,
                Name        = name,
                Pattern     = pattern
            };

            var patterns = settings.Patterns;

            patterns.Add(routePattern);
            settings.Patterns = patterns;

            // define which pattern is the default
            if (makeDefault || settings.Patterns.Count == 1)
            {
                settings.DefaultPatternIndex = settings.Patterns.IndexOf(routePattern);
            }

            _contentDefinitionManager.AlterTypeDefinition(contentType, builder => builder.WithPart("AutoroutePart", settings.Build));
        }
示例#18
0
        public void ContentTypeImported(ContentTypeImportedContext context)
        {
            var part = context.ContentTypeDefinition.Parts
                       .ToList()
                       .Where(p => p.PartDefinition.Name == "CacheEvictorPart")
                       .FirstOrDefault();

            if (part != null)
            {
                if (!string.IsNullOrEmpty(part.Settings.GetModel <CacheEvictorPartSettings>().IdentityEvictItem))
                {
                    string listIds = string.Empty;
                    foreach (var item in part.Settings.GetModel <CacheEvictorPartSettings>().IdentityEvictItem.Split(';'))
                    {
                        var ciIdentity = _contentManager.ResolveIdentity(new ContentIdentity(item));
                        if (ciIdentity != null)
                        {
                            listIds += ciIdentity.Id.ToString() + ";";
                        }
                    }
                    _contentDefinitionManager.AlterTypeDefinition(context.ContentTypeDefinition.Name, cfg => cfg
                                                                  .WithPart(part.PartDefinition.Name,
                                                                            pb => pb.WithSetting("CacheEvictorPartSettings.EvictItem", listIds))
                                                                  );
                }
            }
        }
示例#19
0
        public int Create()
        {
            _contentDefinitionManager.AlterTypeDefinition("Taxonomy", menu => menu
                                                          .Draftable()
                                                          .Versionable()
                                                          .Creatable()
                                                          .Listable()
                                                          .WithPart("TitlePart", part => part.WithPosition("1"))
                                                          .WithPart("AliasPart", part => part.WithPosition("2").WithSettings(new AliasPartSettings {
                Pattern = "{{ ContentItem | display_text | slugify }}"
            }))
                                                          .WithPart("TaxonomyPart", part => part.WithPosition("3"))
                                                          );

            SchemaBuilder.CreateMapIndexTable(nameof(TaxonomyIndex), table => table
                                              .Column <string>("TaxonomyContentItemId", c => c.WithLength(26))
                                              .Column <string>("ContentItemId", c => c.WithLength(26))
                                              .Column <string>("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize))
                                              .Column <string>("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize))
                                              .Column <string>("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize))
                                              .Column <string>("TermContentItemId", column => column.WithLength(26))
                                              );

            SchemaBuilder.AlterTable(nameof(TaxonomyIndex), table => table
                                     .CreateIndex("IDX_TaxonomyIndex_List", "ContentType", "ContentPart", "ContentField")
                                     );

            SchemaBuilder.AlterTable(nameof(TaxonomyIndex), table => table
                                     .CreateIndex("IDX_TaxonomyIndex_Search", "TermContentItemId")
                                     );

            // Return 2 to shortcut the second migration on new content definition schemas.
            return(1);
        }
        public int Create()
        {
            // Now you can configure PersonPart. For example you can add content fields (as mentioned earlier) here.
            _contentDefinitionManager.AlterPartDefinition(nameof(PersonPart), part => part
                                                          // Each field has its own configuration. Here you will give a display name for it and add some
                                                          // additional settings like a hint to be displayed in the editor.
                                                          .WithField(nameof(PersonPart.Biography), field => field
                                                                     .OfType(nameof(TextField))
                                                                     .WithDisplayName("Biography")
                                                                     .Hint("Person's biography")
                                                                     .WithSetting("Editor", "TextArea")));

            // We create a new content type. Note that there's only an alter method: this will create the type if it
            // doesn't exist or modify it if it does. Make sure you understand what content types are:
            // http://docs.orchardproject.net/Documentation/Content-types. The content type's name is arbitrary, but
            // choose a meaningful one. Notice that we attach parts by specifying their name. For our own parts we use
            // nameof(): this is not mandatory but serves great if we change the part's name during development.
            _contentDefinitionManager.AlterTypeDefinition("Person", builder => builder
                                                          .Creatable()
                                                          .Listable()
                                                          .WithPart(nameof(PersonPart))
                                                          );

            // This one will create an index table for the PersonPartIndex as explained in the BookMigrations file.
            SchemaBuilder.CreateMapIndexTable(nameof(PersonPartIndex), table => table
                                              .Column <DateTime>(nameof(PersonPartIndex.BirthDateUtc))
                                              .Column <string>(nameof(PersonPartIndex.ContentItemId), c => c.WithLength(26))
                                              );

            return(1);
        }
示例#21
0
 public static void CreateBasicWidget(this IContentDefinitionManager manager, string name)
 {
     manager.AlterPartDefinition(name, p => p.WithDisplayName(name));
     manager.AlterTypeDefinition(name, t => t.Stereotype("Widget")
                                 .WithPart(name, p => p.WithPosition("0"))
                                 );
 }
        /// <summary>
        /// Migrate existing ContentPart settings to WithSettings<typeparamref name="TSettings"/>
        /// This method will be removed in a future release.
        /// </summary>
        /// <typeparam name="TPart"></typeparam>
        /// <typeparam name="TSettings"></typeparam>
        /// <param name="manager"></param>
        public static void MigratePartSettings <TPart, TSettings>(this IContentDefinitionManager manager)
            where TPart : ContentPart where TSettings : class
        {
            var contentTypes = manager.LoadTypeDefinitions();

            foreach (var contentType in contentTypes)
            {
                var partDefinition = contentType.Parts.FirstOrDefault(x => x.PartDefinition.Name == typeof(TPart).Name);
                if (partDefinition != null)
                {
                    var existingSettings = partDefinition.Settings.ToObject <TSettings>();

                    // Remove existing properties from JObject
                    var properties = typeof(TSettings).GetProperties();
                    foreach (var property in properties)
                    {
                        partDefinition.Settings.Remove(property.Name);
                    }

                    // Apply existing settings to type definition WithSettings<T>
                    manager.AlterTypeDefinition(contentType.Name, typeBuilder =>
                    {
                        typeBuilder.WithPart(partDefinition.Name, partBuilder =>
                        {
                            partBuilder.WithSettings(existingSettings);
                        });
                    });
                }
            }
        }
示例#23
0
        public int Create()
        {
            _contentDefinitionManager.AlterPartDefinition("ProfilePart", builder => builder
                                                          .WithDescription("Links content item to user.")
                                                          .WithDefaultPosition("0")
                                                          );

            _contentDefinitionManager.AlterTypeDefinition(Constants.ContentTypeName, type => type
                                                          .WithPart("ProfilePart")
                                                          );

            SchemaBuilder.CreateMapIndexTable(nameof(ProfilePartIndex), table => table
                                              .Column <string>("UserIdentifier", c => c.WithLength(UserIdenityMaxLength))
                                              );

            SchemaBuilder.AlterTable(nameof(ProfilePartIndex), table => table
                                     .CreateIndex("IDX_ProfilePartIndex_UserIdentifier", "UserIdentifier")
                                     );

            /**
             * Note:
             * Caused an issue on initial orchard recipe setup so commented this out
             */

            // await CreateProfilesForExistingUsersAsync();

            return(2);
        }
示例#24
0
        public int Create()
        {
            //content types
            _contentDefinitionManager.AlterTypeDefinition("MessageRoom", item => item
                                                          .DisplayedAs("Message Room")
                                                          .Draftable()
                                                          .Creatable()
                                                          .Listable()
                                                          .Enabled()
                                                          .Securable()
                                                          .WithPart("MessageRoom") //need to add dummy type part for fields to be attached
                                                          .WithPart("TitlePart", part => part.WithPosition("0"))
                                                          .WithPart("AutoroutePart", part => part.WithPosition("1"))
                                                          .WithPart("CommentPart", part => part.WithPosition("2"))
                                                          // .WithPart("CommonPart", part => part.WithPosition("3").WithSettings(new CommonPartSettings{DisplayDateEditor = true,DisplayOwnerEditor = true}))
                                                          );

            // Fields can not be attached directly to a Content Type. To add fields to a content type, create a part using the same name as the type and add fields to this part.
            _contentDefinitionManager.AlterPartDefinition("MessageRoom", part => part
                                                          .WithField("Members", field => field
                                                                     .OfType(nameof(ContentPickerField))
                                                                     .WithDisplayName("Members")
                                                                     .WithSettings(new ContentPartFieldSettings()
            {
                Position = "0", DisplayName = "Members"
            })
                                                                     .WithSettings(new ContentPickerFieldSettings()
            {
                Multiple = true, Hint = "Select members for the room", DisplayedContentTypes = new[] { "Party" }
            })
                                                                     ));

            return(1);
        }
示例#25
0
        public int Create()
        {
            _contentDefinitionManager.AlterPartDefinition(Constants.RssFeed.ContentType, part => part
                                                          .WithDescription("Create an RSS feed of content.")
                                                          .WithDisplayName(Constants.RssFeed.DisplayName));

            _contentDefinitionManager.AlterPartDefinition(Constants.RssFeed.ContentType, part => part
                                                          .WithField(Constants.RssFeed.SourceFieldName, field => field
                                                                     .OfType(nameof(QueryField))
                                                                     .WithDisplayName(Constants.RssFeed.SourceFieldName)
                                                                     )
                                                          );

            _contentDefinitionManager.AlterTypeDefinition(Constants.RssFeed.ContentType, type => type
                                                          .Draftable()
                                                          .Versionable()
                                                          .Listable()
                                                          .Creatable()
                                                          .Securable()
                                                          .WithPart(nameof(TitlePart))
                                                          .WithPart(Constants.RssFeed.ContentType)
                                                          .DisplayedAs(Constants.RssFeed.DisplayName));

            return(1);
        }
示例#26
0
        public async Task <int> CreateAsync()
        {
            _contentDefinitionManager.AlterPartDefinition(nameof(LeverPostingPart), part => part
                                                          .WithDescription("Create a Lever posting content.")
                                                          .WithDisplayName(Constants.Lever.DisplayName));

            _contentDefinitionManager.AlterTypeDefinition(Constants.Lever.ContentType, type => type
                                                          .Draftable()
                                                          .Versionable()
                                                          .Listable()
                                                          .Creatable()
                                                          .Securable()
                                                          .WithPart(nameof(TitlePart))
                                                          .WithPart("AutoroutePart", part => part.WithSettings(new AutoroutePartSettings
            {
                AllowCustomPath = true,
                Pattern         = "{{ Model.ContentItem | display_text | slugify }}"
            }))
                                                          .WithPart(nameof(LeverPostingPart))
                                                          .DisplayedAs(Constants.Lever.DisplayName));

            SchemaBuilder.CreateMapIndexTable <LeverPostingPartIndex>(table => table
                                                                      .Column <string>("LeverId")
                                                                      );

            SchemaBuilder.AlterTable(nameof(LeverPostingPartIndex), table => table
                                     .CreateIndex("IDX_LeverPostingPartIndex_LeverId", "LeverId")
                                     );

            await _recipeMigrator.ExecuteAsync("create.recipe.json", this);

            return(1);
        }
        public int Create()
        {
            _contentDefinitionManager.AlterPartDefinition("StripePaymentFormPart", builder => builder
                                                          .Attachable()
                                                          .WithDescription("Provides the template needed to display a stripe payment form.")
                                                          .WithField("StripePublishableKey", f => f
                                                                     .OfType("TextField")
                                                                     .WithSettings(new TextFieldSettings()
            {
                Required = true, Hint = "Enter your stripe publishable API key (https://stripe.com/docs/keys)"
            })
                                                                     .WithDisplayName("Stripe Publishable Key")
                                                                     )
                                                          .WithField("StripeSecretKey", f => f
                                                                     .OfType("TextField")
                                                                     .WithSettings(new TextFieldSettings()
            {
                Required = true, Hint = "Enter your stripe secret API key (https://stripe.com/docs/keys)"
            })
                                                                     .WithDisplayName("Stripe Secret Key")
                                                                     )
                                                          );

            _contentDefinitionManager.AlterTypeDefinition("StripePaymentForm", builder => builder
                                                          .Creatable()
                                                          .Listable()
                                                          .WithPart("TitlePart", part => part.WithPosition("1"))
                                                          .WithPart("PaymentPart", part => part.WithPosition("2"))
                                                          .WithPart("StripePaymentFormPart", part => part.WithPosition("3"))
                                                          );

            return(1);
        }
示例#28
0
        public async Task Setup(IDictionary <string, object> properties, Action <string, string> reportError)
        {
            var features = _extensionManager.GetFeatures();

            var featuresToEnable = features.Where(x => x.Id == "ThisNetWorks.OrchardCore.GoogleMaps");

            await _shellFeatureManager.EnableFeaturesAsync(featuresToEnable, true);

            var ctds = _contentDefinitionManager.ListPartDefinitions();

            if (ctds.FirstOrDefault(x => x.Name == "BlogPost") != null)
            {
                _contentDefinitionManager.AlterTypeDefinition("BlogPost", builder => builder
                                                              .WithPart("GoogleMapPart"));

                var query = _session.Query <ContentItem>()
                            .With <ContentItemIndex>(x => x.ContentType == "BlogPost" && x.Published);

                var blogPosts = await query.ListAsync();

                foreach (var blogPost in blogPosts)
                {
                    blogPost.Alter <GoogleMapPart>(part =>
                    {
                        part.Marker = new LatLng {
                            Lat = GoogleMapsSettings.DefaultLatitude, Lng = GoogleMapsSettings.DefaultLongitude
                        };
                    });

                    _session.Save(blogPost);
                }
            }
        }
示例#29
0
        public int Create()
        {
            _contentDefinitionManager.AlterPartDefinition("VueFormSurvey", part => part
                                                          .WithField("SurveyJson", f => f
                                                                     .OfType(nameof(TextField))
                                                                     .WithDisplayName("SurveyJson")
                                                                     .WithSettings(new TextFieldSettings()
            {
                Hint = "Leave blank if not using SurveyJS. Json output of the SurveyJs Creator (https://surveyjs.io/create-survey). With liquid support."
            })
                                                                     .WithPosition("4")
                                                                     .WithEditor("Monaco")
                                                                     .WithSettings(
                                                                         new TextFieldMonacoEditorSettings()
            {
                Options = "{\"language\": \"json\"}"
            })
                                                                     )
                                                          .WithDescription("Adds SurveyJS fields to VueForm"));

            _contentDefinitionManager.AlterTypeDefinition("VueForm", type =>
                                                          type.WithPart("VueFormSurvey", p => p.WithPosition("5"))
                                                          );


            return(1);
        }
        public void Create(MarkdownRepoPart markdownRepoPart, string markdownText, string mdFileRelativePath)
        {
            var markdownContentItem = _contentManager.New(markdownRepoPart.ContentType);

            if (!markdownContentItem.Has(typeof(BodyPart)))
            {
                _contentDefinitionManager.AlterTypeDefinition(
                    markdownContentItem.ContentType,
                    cfg => cfg
                    .WithPart("BodyPart",
                              part => part
                              .WithSetting("BodyTypePartSettings.Flavor", "markdown")));

                markdownContentItem = _contentManager.New(markdownRepoPart.ContentType);
            }

            markdownContentItem.As <BodyPart>().Text = markdownText;
            var markdownPagePart = markdownContentItem.As <MarkdownPagePart>();

            markdownPagePart.MarkdownFilePath = mdFileRelativePath;
            markdownPagePart.MarkdownRepoId   = markdownRepoPart.ContentItem.Id;

            // Creating the content item draft.
            _contentManager.Create(markdownContentItem, VersionOptions.Draft);

            // Firing event so custom extensions can make their own tasks.
            _markdownPageEventHandler
            .MarkdownPageDraftCreated(new MarkdownPageDraftCreatedContext {
                ContentItem = markdownContentItem
            });

            // Publishing the content item.
            _contentManager.Publish(markdownContentItem);
        }
示例#31
0
        // reflection

        public int Create()
        {
            contentDefinitionManager.AlterPartDefinition(
                nameof(PersonPart),
                part => part.Attachable()
                .WithField(nameof(PersonPart.Biography), field => field.OfType(nameof(TextField))
                           .WithDisplayName("Biography")
                           .WithEditor("TextArea")
                           .WithSettings(new TextFieldSettings
            {
                Hint = "Person's biography"
            })));

            SchemaBuilder.CreateMapIndexTable(
                nameof(PersonPartIndex),
                table => table
                .Column <string>(nameof(PersonPartIndex.ContentItemId), x => x.WithLength(26))
                .Column <int>(nameof(PersonPartIndex.Handedness)));
            SchemaBuilder.AlterTable(
                nameof(PersonPartIndex),
                table => table
                .CreateIndex(
                    $"IDX_{nameof(PersonPartIndex)}_{nameof(PersonPartIndex.Handedness)}",
                    nameof(PersonPartIndex.Handedness)));

            contentDefinitionManager.AlterTypeDefinition("PersonWidget", type => type
                                                         .DisplayedAs("Person Widget")
                                                         .Draftable()
                                                         .Versionable()
                                                         .WithPart("PersonPage")
                                                         .WithPart("PersonPart")
                                                         .Stereotype("Widget")); // categorization for content types

            return(1);
        }
 public static void SetupRepoPageContentType(IContentDefinitionManager contentDefinitionManager, string pageContentTypeName)
 {
     contentDefinitionManager.AlterTypeDefinition(pageContentTypeName,
         cfg => cfg
             .WithPart("TitlePart")
             .WithPart("CommonPart")
             .WithPart("AutoroutePart", builder => builder
                 .WithSetting("AutorouteSettings.AllowCustomPattern", "false")
                 .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "true")
                 .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Title', Pattern: '{Content.Slug}', Description: 'my-page'}]")
                 .WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
             .WithPart(typeof(MarkdownPagePart).Name)
             .WithPart("BodyPart", builder => builder
                 .WithSetting("BodyTypePartSettings.Flavor", "markdown"))
         );
 }