/// <summary> /// Creates a <see cref="PageModel"/> object based off of then given <see cref="SiteMapNode"/> /// object. /// </summary> /// <param name="sfContent">The sf content.</param> /// <param name="includeParents">true to include, false to exclude the parents.</param> /// <param name="includeChildren">true to include, false to exclude the children.</param> /// <param name="includeRelatedData">true to include, false to exclude the related data.</param> /// <returns> /// A new <see cref="PageModel"/> object. /// </returns> public PageModel Create(SiteMapNode sfContent, bool includeParents, bool includeChildren, bool includeRelatedData) { var pageModel = new PageModel(sfContent); var pageNode = sfContent as PageSiteNode; if (pageNode == null) { return(pageModel); } pageModel.Id = pageNode.Id; pageModel.Title = pageNode.Title; pageModel.Description = pageNode.Description; pageModel.Url = _webHelper.ResolveUrl(pageNode.Url); pageModel.Crawlable = pageNode.Crawlable; pageModel.IsBackend = pageNode.IsBackend; pageModel.NodeType = pageNode.NodeType; pageModel.LinkTarget = _pageHelper.GetLinkTarget(pageNode); pageModel.ShowInNavigation = pageNode.ShowInNavigation; pageModel.SafeName = _webHelper.GenerateSafeName(pageNode.UrlName); pageModel.Ordinal = pageNode.Ordinal; pageModel.Status = pageNode.Status; pageModel.Theme = pageNode.Theme; pageModel.Framework = pageNode.Framework.ToString(); pageModel.Slug = pageNode.UrlName; pageModel.Active = pageNode.Status == ContentLifecycleStatus.Live && pageNode.Visible; pageModel.CustomFields = pageNode.GetCustomFieldValues(includeRelatedData); if (includeParents) { pageModel.Parent = Create(sfContent.ParentNode, false, false, includeRelatedData); } //GET CHILDREN PAGES IF APPLICABLE if (!includeChildren || !pageNode.HasChildNodes) { return(pageModel); } foreach (PageSiteNode item in pageNode.ChildNodes) { bool itemIsLiveStandard = item.NodeType == NodeType.Standard && item.Status == ContentLifecycleStatus.Live; bool itemIsMasterNonStandard = item.NodeType != NodeType.Standard && item.Status == ContentLifecycleStatus.Master; bool itemIsPublishedButHasDraft = item.NodeType == NodeType.Standard && item.Status == ContentLifecycleStatus.Master && item.Visible; if (item.ShowInNavigation && (itemIsLiveStandard || itemIsMasterNonStandard || itemIsPublishedButHasDraft)) { //ADD PAGE AND LEAVE OUT PARENT NODE pageModel.Items.Add(Create(item, false, true, includeRelatedData)); } } return(pageModel); }
/// <summary> /// Registers widget to the toolbox. http://www.sitefinity.com/developer-network/forums/general- /// discussions-/registering-custom-control-in-toolbox. /// </summary> /// <typeparam name="T">Generic type parameter.</typeparam> /// <param name="title">The title.</param> /// <param name="description">(Optional) The description.</param> /// <param name="cssClass">(Optional) The CSS class.</param> /// <param name="resourceClassId">(Optional) The resource class identifier.</param> /// <param name="layoutTemplate">(Optional) The layout template.</param> /// <param name="sectionName">(Optional) Name of the section.</param> /// <param name="sectionOrdinal">(Optional) The section ordinal.</param> /// <param name="toolboxType">(Optional) Type of the toolbox.</param> public static void RegisterToolboxWidget <T>(string title, string description = null, string cssClass = null, string resourceClassId = null, string layoutTemplate = "", string sectionName = Constants.VALUE_TOOLBOX_SECTION_NAME, int?sectionOrdinal = null, ToolboxType toolboxType = ToolboxType.PageControls) { var manager = Config.GetManager(); using (new ElevatedModeRegion(manager)) { var config = manager.GetSection <ToolboxesConfig>(); //GET PAGE TOOLBOX var controls = config.Toolboxes[toolboxType.ToString()]; var section = controls .Sections .FirstOrDefault <ToolboxSection>(x => x.Name == sectionName); //CREATE THE SECTION IF APPLICABLE if (section == null) { section = new ToolboxSection(controls.Sections) { Name = _webHelper.GenerateSafeName(sectionName, true), Title = sectionName, Description = sectionName, Ordinal = sectionOrdinal.GetValueOrDefault(99) }; //SET ORDINALS FOR SECTIONS if (sectionOrdinal.HasValue) { //HANDLE ORDINAL CONFLICTS foreach (var item in controls.Sections .Where <ToolboxSection>(x => x.Ordinal == sectionOrdinal.Value)) { item.Ordinal += 0.1F; } } controls.Sections.Add(section); } //REGISTER IN TOOLBOX IF APPLICABLE var control = typeof(T); if (!section.Tools.Any <ToolboxItem>(t => t.Name == control.Name)) { //GENERATE NAME FOR TOOLBOX ITEM var name = _webHelper.GenerateSafeName(title, true); //VALIDATE NAME if (Char.IsNumber(name, 0)) { name = section.Name + name; } //CREATE WIDGET OBJECT var widget = new ToolboxItem(section.Tools) { Name = name, Title = title, Description = description ?? title, CssClass = cssClass, ResourceClassId = resourceClassId }; //HANDLE WEB FORM AND MVC WIDGETS DIFFERENTLY if (typeof(Controller).IsAssignableFrom(control)) { //DEFINE AS MVC WIDGET widget.ControlType = string.Format("{0}, {1}", typeof(MvcControllerProxy).FullName, typeof(MvcControllerProxy).Assembly); widget.ControllerType = control.FullName; widget.Parameters.Add("ControllerName", control.FullName); } else { //DEFINE AS WEB FORM WIDGET widget.ControlType = control.FullName; } //ASSIGN TEMPLATE IF APPLICABLE if (!string.IsNullOrWhiteSpace(layoutTemplate)) { widget.LayoutTemplate = layoutTemplate; } //REGISTER TO SYSTEM section.Tools.Add(widget); manager.SaveSection(config); } } }