/// <summary> /// The find pages with criteria. /// </summary> /// <param name="pageLink"> /// The page link. /// </param> /// <param name="criterias"> /// The criterias. /// </param> /// <param name="languageBranch"> /// The language branch. /// </param> /// <param name="selector"> /// The selector. /// </param> /// <returns> /// The <see cref="PageDataCollection"/>. /// </returns> public PageDataCollection FindPagesWithCriteria( PageReference pageLink, PropertyCriteriaCollection criterias, string languageBranch, ILanguageSelector selector) { if (PageReference.IsNullOrEmpty(pageLink)) { return(new PageDataCollection()); } // Any search beneath the entry root should in fact be performed under the clone root as that's where the original content resides if (pageLink.CompareToIgnoreWorkID(this.EntryRoot)) { pageLink = this.CloneRoot; } else if (!string.IsNullOrWhiteSpace(pageLink.ProviderName)) { // Any search beneath a cloned page should in fact be performed under the original page, so we use a page link without any provider information pageLink = new PageReference(pageLink.ID); } PageDataCollection pages = DataFactory.Instance.FindPagesWithCriteria( pageLink, criterias, languageBranch, selector); // Return cloned search result set return(new PageDataCollection(pages.Select(this.ClonePage))); }
/// <summary> /// Initializes a new instance of the <see cref="ClonedContentProvider"/> class. /// </summary> /// <param name="providerKey"> /// The provider key. /// </param> /// <param name="cloneRoot"> /// The clone root. /// </param> /// <param name="entryRoot"> /// The entry root. /// </param> /// <param name="categoryFilter"> /// The category filter. /// </param> /// <exception cref="System.ArgumentNullException"> /// Parameter "cloneRoot" cannot be null or empty /// </exception> /// <exception cref="System.NotSupportedException"> /// Entry root and clone root cannot be set to the same content reference /// or /// Unable to create ClonedContentProvider, the EntryRoot property must point to leaf content (without children) /// </exception> public ClonedContentProvider( string providerKey, PageReference cloneRoot, PageReference entryRoot, CategoryList categoryFilter) { if (PageReference.IsNullOrEmpty(cloneRoot)) { throw new ArgumentNullException("cloneRoot"); } if (cloneRoot.CompareToIgnoreWorkID(entryRoot)) { throw new NotSupportedException("Entry root and clone root cannot be set to the same content reference"); } if (DataFactory.Instance.GetChildren <IContent>(entryRoot).Any()) { throw new NotSupportedException( "Unable to create ClonedContentProvider, the EntryRoot property must point to leaf content (without children)"); } this.CloneRoot = cloneRoot; this.EntryRoot = entryRoot; this.Category = categoryFilter; this.providerKey = providerKey; // Set the entry point parameter this.Parameters.Add(PageProvider.EntryPointString, this.EntryRoot.ID.ToString(CultureInfo.InvariantCulture)); // Configure content store used to retrieve pages this.ContentStore = ServiceLocator.Current.GetInstance <ContentStore>(); }
/// <summary> /// Shorthand for DataFactory.Instance.GetPage /// </summary> public static T GetPage <T>(this PageReference pageLink) where T : PageData { if (pageLink.CompareToIgnoreWorkID(PageReference.RootPage)) { throw new NotSupportedException("The root page cannot be converted to type " + typeof(T).Name); } return((T)DataFactory.Instance.GetPage(pageLink)); }
public static void RenderMainNavigation(this HtmlHelper html, PageReference rootLink = null, ContentReference contentLink = null, bool includeRoot = true, IContentLoader contentLoader = null) { contentLink = contentLink ?? html.ViewContext.RequestContext.GetContentLink(); rootLink = rootLink ?? ContentReference.StartPage; var writer = html.ViewContext.Writer; // top level writer.WriteLine("<nav class=\"navbar navbar-inverse\">"); writer.WriteLine("<ul class=\"nav navbar-nav\">"); if (includeRoot) { if (rootLink.CompareToIgnoreWorkID(contentLink)) { writer.WriteLine("<li class=\"active\">"); } else { writer.WriteLine("<li>"); } writer.WriteLine(html.PageLink(rootLink).ToHtmlString()); writer.WriteLine("</li>"); } // hämta ut alla barn från start contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>(); var topLevelPages = contentLoader.GetChildren<PageData>(rootLink); topLevelPages = FilterForVisitor.Filter(topLevelPages).OfType<PageData>().Where(x => x.VisibleInMenu); var currentBranch = contentLoader.GetAncestors(contentLink).Select(x => x.ContentLink).ToList(); currentBranch.Add(contentLink); //skriv ut dom foreach (var topLevelPage in topLevelPages) { if (currentBranch.Any(x => x.CompareToIgnoreWorkID(topLevelPage.ContentLink))) { writer.WriteLine("<li class=\"active\">"); } else { writer.WriteLine("<li>"); } writer.WriteLine(html.PageLink(topLevelPage).ToHtmlString()); writer.WriteLine("</li>"); } //Close top level writer.WriteLine("</ul"); writer.WriteLine("</nav>"); }
/// <summary> /// <see cref="PageProviderBase.GetChildrenReferences(EPiServer.Core.PageReference,string)"/> /// </summary> /// <param name="pageLink">Page Link</param> /// <param name="languageID">Language Id</param> /// <returns>Page reference collection</returns> protected override PageReferenceCollection GetChildrenReferences(PageReference pageLink, string languageID) { if (pageLink == null || PageReference.IsNullOrEmpty(pageLink)) { return new PageReferenceCollection(); } if (pageLink.CompareToIgnoreWorkID(EntryPoint)) { return new PageReferenceCollection(RootChildren.Select(key => new PageReference((MappedPPDB.Instance.LoadMapping(Name, key).Id), this.ProviderKey)).ToArray()); } var children = GetChildren(MappedPPDB.Instance.LoadMapping(Name, pageLink.ID).Key); return children == null ? new PageReferenceCollection() : new PageReferenceCollection(children.Select(key => new PageReference(MappedPPDB.Instance.LoadMapping(Name, key).Id, this.ProviderKey)).ToArray()); }
public ClonedContentProvider(PageReference cloneRoot, PageReference entryRoot, CategoryList categoryFilter) { if (cloneRoot.CompareToIgnoreWorkID(entryRoot)) { throw new NotSupportedException("Entry root and clone root cannot be set to the same content reference"); } if (ServiceLocator.Current.GetInstance <IContentLoader>().GetChildren <IContent>(entryRoot).Any()) { throw new NotSupportedException("Unable to create ClonedContentProvider, the EntryRoot property must point to leaf content (without children)"); } CloneRoot = cloneRoot; EntryRoot = entryRoot; Category = categoryFilter; // Set the entry point parameter Parameters.Add(ContentProviderElement.EntryPointString, EntryRoot.ID.ToString(CultureInfo.InvariantCulture)); }
public ClonedContentProvider(PageReference cloneRoot, PageReference entryRoot, CategoryList categoryFilter) { if (cloneRoot.CompareToIgnoreWorkID(entryRoot)) { throw new NotSupportedException("Entry root and clone root cannot be set to the same content reference"); } if (DataFactory.Instance.GetChildren<IContent>(entryRoot).Any()) { throw new NotSupportedException("Unable to create ClonedContentProvider, the EntryRoot property must point to leaf content (without children)"); } CloneRoot = cloneRoot; EntryRoot = entryRoot; Category = categoryFilter; // Set the entry point parameter Parameters.Add(Configuration.PageProvider.EntryPointString, EntryRoot.ID.ToString(CultureInfo.InvariantCulture)); // Configure content store used to retrieve pages ContentStore = ServiceLocator.Current.GetInstance<ContentStore>(); }
public static void RenderMainNavigation( this HtmlHelper html, PageReference rootLink = null, ContentReference contentLink = null, bool includeRoot = true, IContentLoader contentLoader = null) { contentLink = contentLink ?? html.ViewContext.RequestContext.GetContentLink(); rootLink = rootLink ?? ContentReference.StartPage; var writer = html.ViewContext.Writer; //Top level elements writer.WriteLine("<nav class=\"navbar navbar-inverse\">"); writer.WriteLine("<ul class=\"nav navbar-nav\">"); if (includeRoot) { //Link to the root page if (rootLink.CompareToIgnoreWorkID(contentLink)) { writer.WriteLine("<li class=\"active\">"); } else { writer.WriteLine("<li>"); } writer.WriteLine( html.PageLink(rootLink).ToHtmlString()); writer.WriteLine("</li>"); } //Retrieve and filter the root pages children contentLoader = contentLoader ?? ServiceLocator.Current.GetInstance <IContentLoader>(); var topLevelPages = contentLoader .GetChildren <PageData>(rootLink); topLevelPages = FilterForVisitor.Filter(topLevelPages) .OfType <PageData>() .Where(x => x.VisibleInMenu); //Retrieve the "path" from the current page up to the //root page in the content tree in order to check if //a link should be highlighted. var currentBranch = contentLoader.GetAncestors(contentLink) .Select(x => x.ContentLink) .ToList(); currentBranch.Add(contentLink); //Link to the root pages children foreach (var topLevelPage in topLevelPages) { if (currentBranch.Any(x => x.CompareToIgnoreWorkID(topLevelPage.ContentLink))) { writer.WriteLine("<li class=\"active\">"); } else { writer.WriteLine("<li>"); } writer.WriteLine(html.PageLink(topLevelPage).ToHtmlString()); writer.WriteLine("</li>"); } //Close top level element writer.WriteLine("</ul>"); writer.WriteLine("</nav>"); }
/// <summary> /// Convert page reference to key /// </summary> /// <param name="pageReference">Page reference</param> /// <returns>Key</returns> protected string ConvertPageReference(PageReference pageReference) { if (pageReference == null || PageReference.IsNullOrEmpty(pageReference)) { return null; } return pageReference.CompareToIgnoreWorkID(EntryPoint) ? null : GetMapping(pageReference.ID).Key; }
public PageDataCollection FindPagesWithCriteria(PageReference pageLink, PropertyCriteriaCollection criterias, string languageBranch, ILanguageSelector selector) { // Any search beneath the entry root should in fact be performed under the clone root as that's where the original content resides if (pageLink.CompareToIgnoreWorkID(EntryRoot)) { pageLink = CloneRoot; } else if (!string.IsNullOrWhiteSpace(pageLink.ProviderName)) // Any search beneath a cloned page should in fact be performed under the original page, so we use a page link without any provider information { pageLink = new PageReference(pageLink.ID); } var pages = DataFactory.Instance.FindPagesWithCriteria(pageLink, criterias, languageBranch, selector); // Return cloned search result set return new PageDataCollection(pages.Select(ClonePage)); }
public static void RenderMainNavigation( this HtmlHelper html, PageReference rootLink = null, ContentReference contentLink = null, bool includeRoot = true, IContentLoader contentLoader = null) { contentLink = contentLink ?? html.ViewContext.RequestContext.GetContentLink(); rootLink = rootLink ?? ContentReference.StartPage; var writer = html.ViewContext.Writer; //Top level elements writer.WriteLine("<nav class=\"navbar navbar-inverse\">"); writer.WriteLine("<ul class=\"nav navbar-nav\">"); if (includeRoot) { //Link to the root page if (rootLink.CompareToIgnoreWorkID(contentLink)) { writer.WriteLine("<li class=\"active\">"); } else { writer.WriteLine("<li>"); } writer.WriteLine( html.PageLink(rootLink).ToHtmlString()); writer.WriteLine("</li>"); } //Retrieve and filter the root pages children contentLoader = contentLoader ?? ServiceLocator.Current.GetInstance<IContentLoader>(); var topLevelPages = contentLoader .GetChildren<PageData>(rootLink); topLevelPages = FilterForVisitor.Filter(topLevelPages) .OfType<PageData>() .Where(x => x.VisibleInMenu); //Retrieve the "path" from the current page up to the //root page in the content tree in order to check if //a link should be highlighted. var currentBranch = contentLoader.GetAncestors(contentLink) .Select(x => x.ContentLink) .ToList(); currentBranch.Add(contentLink); //Link to the root pages children foreach (var topLevelPage in topLevelPages) { if (currentBranch.Any(x => x.CompareToIgnoreWorkID(topLevelPage.ContentLink))) { writer.WriteLine("<li class=\"active\">"); } else { writer.WriteLine("<li>"); } writer.WriteLine(html.PageLink(topLevelPage).ToHtmlString()); writer.WriteLine("</li>"); } //Close top level element writer.WriteLine("</ul>"); writer.WriteLine("</nav>"); }
/// <summary> /// /// </summary> /// <param name="html"></param> /// <param name="rootLink"></param> /// <param name="contentLink"></param> /// <param name="includeRoot"></param> /// <param name="contentLoader"></param> public static void RenderMainNavigation(this HtmlHelper html, PageReference rootLink = null, ContentReference contentLink = null, bool includeRoot = true, IContentLoader contentLoader = null) { contentLink = contentLink ?? html.ViewContext.RequestContext.GetContentLink(); rootLink = rootLink ?? ContentReference.StartPage; var writer = html.ViewContext.Writer; writer.WriteLine("<nav class='navbar navbar-expand-md navbar-light bg-light'>"); writer.WriteLine("<a class='navbar-brand' href='#'>Acquire EPiServer</a>"); writer.WriteLine("<button class='navbar-toggler' type='button' data-toggle='collapse' data-target='#navbarSupportedContent' aria-controls='navbarSupportedContent' aria-expanded='false' aria-label='Toggle navigation'>"); writer.WriteLine("<span class='navbar-toggler-icon'></span>"); writer.WriteLine("</button>"); writer.WriteLine("<div class='collapse navbar-collapse' id='navbarSupportedContent'>"); writer.WriteLine("<ul class='navbar-nav mr-auto'>"); if (includeRoot) { if (rootLink.CompareToIgnoreWorkID(contentLink)) { writer.WriteLine("<li class=\"active nav-item\">"); } else { writer.WriteLine("<li class=\"nav-item\">"); } writer.WriteLine(html.PageLink(rootLink, null, new { @class = "nav-link" }).ToHtmlString()); writer.WriteLine("</li>"); } contentLoader = contentLoader ?? ServiceLocator.Current.GetInstance <IContentLoader>(); var topLevelPages = contentLoader.GetChildren <PageData>(rootLink); // Filtering out the pages which should not be appeared in the menu topLevelPages = FilterForVisitor.Filter(topLevelPages).OfType <PageData>().Where(x => x.VisibleInMenu); var currentBranch = contentLoader.GetAncestors(contentLink).Select(x => x.ContentLink).ToList(); currentBranch.Add(contentLink); // Processing further with top level pages foreach (var topLevelPage in topLevelPages) { // Checking if current location is equal to content link. if (currentBranch.Any(x => x.CompareToIgnoreWorkID(topLevelPage.ContentLink))) { writer.WriteLine("<li class=\"active nav-item\">"); } else { writer.WriteLine("<li class=\"nav-item\">"); } writer.WriteLine(html.PageLink(topLevelPage, null, new { @class = "nav-link" }).ToHtmlString()); writer.WriteLine("</li>"); } writer.WriteLine("</ul>"); writer.WriteLine("<form class='form-inline my-2 my-lg-0'>"); writer.WriteLine("<input class='form-control mr-sm-2' type='search' placeholder='Search' aria-label='Search'>"); writer.WriteLine("<button class='btn btn-outline-success my-2 my-sm-0' type='submit'>Search</button>"); writer.WriteLine("</form>"); writer.WriteLine("</div>"); writer.WriteLine("</nav>"); }