public void AddSharedContentBlockWidgetToPage(Guid pageId, string contentBlockTitle, string placeholder = "Body") { PageManager pageManager = PageManager.GetManager(); pageManager.Provider.SuppressSecurityChecks = true; var pageDataId = pageManager.GetPageNode(pageId).PageId; var page = pageManager.EditPage(pageDataId, CultureInfo.CurrentUICulture); var content = App.WorkWith().ContentItems() .Published() .Where(c => c.Title == contentBlockTitle) .Get().Single(); using (var mvcWidget = new Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy()) { mvcWidget.ControllerName = typeof(ContentBlockController).FullName; mvcWidget.Settings = new Telerik.Sitefinity.Mvc.Proxy.ControllerSettings(new ContentBlockController() { Content = content.Content.Value, SharedContentID = content.Id }); this.CreateControl(pageManager, page, mvcWidget, "ContentBlock", placeholder); } }
private PageNode CreatePageTemplateHierarchy(ref Guid templateId1, ref Guid templateId2) { var widgetName = "ContentBlock"; var widgetName1 = "News widget"; var widgetName2 = "Blog post widget"; var template1Name = "Template1"; var template2Name = "Template2"; templateId1 = ServerOperationsFeather.TemplateOperations().DuplicatePageTemplate(PageTemplateName, template1Name); var mvcWidget1 = new Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy(); mvcWidget1.ControllerName = typeof(NewsController).FullName; mvcWidget1.Settings = new Telerik.Sitefinity.Mvc.Proxy.ControllerSettings(new NewsController()); ServerOperationsFeather.TemplateOperations().AddControlToTemplate(templateId1, mvcWidget1, "Contentplaceholder1", widgetName1); templateId2 = ServerOperationsFeather.TemplateOperations().CreatePageTemplate(template2Name, templateId1); var mvcWidget2 = new Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy(); mvcWidget2.ControllerName = typeof(BlogPostController).FullName; mvcWidget2.Settings = new Telerik.Sitefinity.Mvc.Proxy.ControllerSettings(new BlogPostController()); mvcWidget2.ID = widgetName2.Replace(" ", string.Empty); ServerOperationsFeather.TemplateOperations().AddControlToTemplate(templateId2, mvcWidget2, "Contentplaceholder1", widgetName2); var pageId = ServerOperations.Pages().CreatePage("TestPage1", templateId2); var pageNodeId = ServerOperations.Pages().GetPageNodeId(pageId); var pageManager = Telerik.Sitefinity.Modules.Pages.PageManager.GetManager(); var pageNode = pageManager.GetPageNode(pageNodeId); ServerOperationsFeather.Pages().AddContentBlockWidgetToPage(pageNodeId, widgetName, "Contentplaceholder1"); return(pageNode); }
/// <summary> /// Creates the mvcWidget control. /// </summary> /// <param name="pageManager">The page manager.</param> /// <param name="page">The page.</param> /// <param name="mvcWidget">The MVC widget.</param> private void CreateControl(PageManager pageManager, PageDraft page, Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy mvcWidget, string widgetCaption, string placeholder = "Body") { var draftControlDefault = pageManager.CreateControl <PageDraftControl>(mvcWidget, placeholder); draftControlDefault.Caption = widgetCaption; pageManager.SetControlDefaultPermissions(draftControlDefault); page.Controls.Add(draftControlDefault); pageManager.PublishPageDraft(page, CultureInfo.CurrentUICulture); pageManager.SaveChanges(); }
public void AddCardWidgetToPage(Guid pageId, string placeholder = "Body") { PageManager pageManager = PageManager.GetManager(); pageManager.Provider.SuppressSecurityChecks = true; var pageDataId = pageManager.GetPageNode(pageId).PageId; var page = pageManager.EditPage(pageDataId, CultureInfo.CurrentUICulture); using (var mvcWidget = new Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy()) { mvcWidget.ControllerName = typeof(CardController).FullName; this.CreateControl(pageManager, page, mvcWidget, "Card", placeholder); } }
/// <summary> /// Add blog posts widget to existing page. /// </summary> /// <param name="pageId">The page Id.</param> /// <param name="placeholder">The placeholderId.</param> /// <param name="parentFilterMode">The parent filter mode.</param> public void AddBlogPostsWidgetToPage(Guid pageId, string placeholder, ParentFilterMode parentFilterMode) { PageManager pageManager = PageManager.GetManager(); pageManager.Provider.SuppressSecurityChecks = true; var pageDataId = pageManager.GetPageNode(pageId).PageId; var page = pageManager.EditPage(pageDataId, CultureInfo.CurrentUICulture); using (var mvcWidget = new Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy()) { mvcWidget.ControllerName = typeof(BlogPostController).FullName; var controller = new BlogPostController(); controller.Model.ParentFilterMode = parentFilterMode; mvcWidget.Settings = new ControllerSettings(controller); this.CreateControl(pageManager, page, mvcWidget, "Blog posts", placeholder); } }
/// <summary> /// Creates the mvcWidget control. /// </summary> /// <param name="pageManager">The page manager.</param> /// <param name="page">The page.</param> /// <param name="mvcWidget">The MVC widget.</param> private void CreateControl(PageManager pageManager, PageDraft page, Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy mvcWidget, string widgetCaption, string placeholder = "Body") { var draftControlDefault = pageManager.CreateControl <PageDraftControl>(mvcWidget, placeholder); draftControlDefault.Caption = widgetCaption; pageManager.SetControlDefaultPermissions(draftControlDefault); var firstControl = page.Controls.FirstOrDefault(c => c.PlaceHolder == placeholder && c.SiblingId == Guid.Empty); if (firstControl != null) { draftControlDefault.SiblingId = Guid.Empty; firstControl.SiblingId = draftControlDefault.Id; } page.Controls.Add(draftControlDefault); pageManager.PublishPageDraft(page, CultureInfo.CurrentUICulture); pageManager.SaveChanges(); }
public void AddListsWidgetToPage(Guid pageId, Guid listId, string templateName, string placeholder = "Body") { PageManager pageManager = PageManager.GetManager(); pageManager.Provider.SuppressSecurityChecks = true; var pageDataId = pageManager.GetPageNode(pageId).PageId; var page = pageManager.EditPage(pageDataId, CultureInfo.CurrentUICulture); using (var mvcProxy = new Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy()) { mvcProxy.ControllerName = typeof(ListsController).FullName; var listsController = new ListsController(); listsController.ListTemplateName = templateName; listsController.Model.SerializedSelectedItemsIds = "[" + listId.ToString() + "]"; mvcProxy.Settings = new ControllerSettings(listsController); this.CreateControl(pageManager, page, mvcProxy, "Lists", placeholder); } }