/// <summary> /// Gets all navigation nodes based on the navigation query parameters. /// </summary> /// <param name="queryParameters">The query parameters.</param> /// <returns>A hierarchy of navigation nodes.</returns> public IEnumerable <NavigationNode> GetAllNavigationNodes(NavigationQueryParameters queryParameters) { INavigationService navigationService; SPWeb currentWeb = SPContext.Current.Web; using (var scope = DynamiteWspContainerProxy.BeginLifetimeScope(currentWeb)) { navigationService = scope.Resolve <INavigationService>(); } return(navigationService.GetAllNavigationNodes(currentWeb, queryParameters)); }
/// <summary> /// Loads the data in the page /// </summary> /// <param name="sender">The sender</param> /// <param name="e">The arguments</param> protected void Page_Load(object sender, EventArgs e) { var serializer = new JavaScriptSerializer(); using (var scope = NavigationContainerProxy.BeginWebLifetimeScope(SPContext.Current.Web)) { var navigationService = scope.Resolve<INavigationService>(); var publishingFieldInfoConfig = scope.Resolve<IPublishingFieldInfoConfig>(); var navigationField = publishingFieldInfoConfig.GetFieldById(PublishingFieldInfos.Navigation.Id) as TaxonomyFieldInfo; var queryParameters = new NavigationQueryParameters() { NodeMatchingSettings = new NavigationNodeMatchingSettings() { IncludeCatalogItems = true, RestrictToReachableTargetItems = true, }, SearchSettings = new NavigationSearchSettings() { NavigationManagedPropertyName = navigationField.OWSTaxIdManagedPropertyInfo.Name, ResultSourceName = NavigationResultSourceInfos.AllMenuItems.Name, SelectedProperties = new List<string> { // These properties are required for the generation of the friendly URL navigationField.OWSTaxIdManagedPropertyInfo.Name, BuiltInManagedProperties.Url.Name, BuiltInManagedProperties.SiteUrl.Name, BuiltInManagedProperties.ListId.Name }, GlobalFilters = new List<string> { // Use the Locale of the web instead of the Language because when we implement unsupported languages as Inuktitut, // the variation label language is en-US. // Filter items on the web's language string.Format( CultureInfo.InvariantCulture, "{0}:{1}", MultilingualismManagedPropertyInfos.ItemLanguage.Name, SPContext.Current.Web.Locale.Name), // Filter items on occurence link location (featured in) main menu string.Format( CultureInfo.InvariantCulture, "{0}:{1}", NavigationManagedPropertyInfos.OccurrenceLinkLocationManagedPropertyText.Name, "Main Menu") }, TargetItemFilters = new List<string> { string.Format( CultureInfo.InvariantCulture, "{0}:{1}*", BuiltInManagedProperties.ContentTypeId.Name, PublishingContentTypeInfos.TargetContentItem.ContentTypeId) }, CatalogItemFilters = new List<string> { string.Format( CultureInfo.InvariantCulture, "{0}:{1}*", BuiltInManagedProperties.ContentTypeId.Name, PublishingContentTypeInfos.CatalogContentItem.ContentTypeId) } } }; // Call the navigation service var navigationData = navigationService.GetAllNavigationNodes(SPContext.Current.Web, queryParameters); // Serializes the data this.MenuJson = serializer.Serialize(navigationData); } }