public virtual ActionResult Navigation(EntityModel entity, string navType, int containerSize = 0) { using (new Tracer(entity, navType, containerSize)) { SetupViewData(entity, containerSize); INavigationProvider navigationProvider = SiteConfiguration.NavigationProvider; string requestUrlPath = Request.Url.LocalPath; Localization localization = WebRequestContext.Localization; NavigationLinks model; switch (navType) { case "Top": model = navigationProvider.GetTopNavigationLinks(requestUrlPath, localization); break; case "Left": model = navigationProvider.GetContextNavigationLinks(requestUrlPath, localization); break; case "Breadcrumb": model = navigationProvider.GetBreadcrumbNavigationLinks(requestUrlPath, localization); break; default: throw new DxaException("Unexpected navType: " + navType); } EntityModel sourceModel = (EnrichModel(entity) as EntityModel) ?? entity; model.XpmMetadata = sourceModel.XpmMetadata; model.XpmPropertyMetadata = sourceModel.XpmPropertyMetadata; return(View(sourceModel.MvcData.ViewName, model)); } }
public void GetTopNavigationLinks_Success() { ILocalization testLocalization = TestFixture.ParentLocalization; NavigationLinks testNavLinks = _testNavigationProvider.GetTopNavigationLinks(testLocalization.Path, testLocalization); Assert.IsNotNull(testNavLinks, "NavigationLinks"); AssertValidHomePageLink(testNavLinks, testLocalization); }
public void GetTopNavigationLinks_Root_Success() { Localization testLocalization = TestFixture.ParentLocalization; NavigationLinks navLinks = _testNavigationProvider.GetTopNavigationLinks(testLocalization.Path, testLocalization); Assert.IsNotNull(navLinks, "navLinks"); OutputJson(navLinks); Assert.AreEqual(1, navLinks.Items.Count, "navLinks.Items.Count"); AssertValidLink(navLinks.Items[0], "/autotest-parent/regression/taxonomy", TestFixture.TopLevelKeyword2Title, "Top-level Keyword 2 (concrete)", "navLinks.Items[0]"); }
/// <summary> /// Gets Navigation Links for the top navigation menu for the given request URL path. /// </summary> /// <param name="requestUrlPath">The request URL path.</param> /// <param name="localization">The Localization.</param> /// <returns>The Navigation Links.</returns> public NavigationLinks GetTopNavigationLinks(string requestUrlPath, Localization localization) { using (new Tracer(requestUrlPath, localization)) { SitemapItem rootSitemapItem = GetNavigationModel(localization); if (!(rootSitemapItem is TaxonomyNode)) { // No Navigation Taxonomy found in this Localization; fallback to the StaticNavigationProvider. return(_fallbackNavigationProvider.GetTopNavigationLinks(requestUrlPath, localization)); } return(new NavigationLinks { Items = rootSitemapItem.Items.Where(i => i.Visible).Select(i => i.CreateLink(localization)).ToList() }); } }