private async Task PopulateContainedContentItemIndexesAsync(List <AutoroutePartIndex> results, ContentItem containerContentItem, ContainedContentItemsAspect containedContentItemsAspect, JObject content, string basePath) { foreach (var accessor in containedContentItemsAspect.Accessors) { var items = accessor.Invoke(content); foreach (JObject jItem in items) { var contentItem = jItem.ToObject <ContentItem>(); var handlerAspect = await _contentManager.PopulateAspectAsync <RouteHandlerAspect>(contentItem); if (!handlerAspect.Disabled) { var path = handlerAspect.Path; if (!handlerAspect.Absolute) { path = (basePath.EndsWith('/') ? basePath : basePath + '/') + handlerAspect.Path; } results.Add(new AutoroutePartIndex { ContentItemId = containerContentItem.ContentItemId, Path = path, Published = containerContentItem.Published, Latest = containerContentItem.Latest, ContainedContentItemId = contentItem.ContentItemId, JsonPath = jItem.Path }); } var itemBasePath = (basePath.EndsWith('/') ? basePath : basePath + '/') + handlerAspect.Path; var childrenAspect = await _contentManager.PopulateAspectAsync <ContainedContentItemsAspect>(contentItem); await PopulateContainedContentItemIndexesAsync(results, containerContentItem, childrenAspect, jItem, itemBasePath); } } }
private async Task ValidateContainedContentItemRoutes(List <AutorouteEntry> entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JObject content, string basePath) { foreach (var accessor in containedContentItemsAspect.Accessors) { var jItems = accessor.Invoke(content); foreach (JObject jItem in jItems) { var contentItem = jItem.ToObject <ContentItem>(); var containedAutoroutePart = contentItem.As <AutoroutePart>(); // This is only relevant if the content items have an autoroute part as we adjust the part value as required to guarantee a unique route. // Content items routed only through the handler aspect already guarantee uniqueness. if (containedAutoroutePart != null && !containedAutoroutePart.Disabled) { var path = containedAutoroutePart.Path; if (containedAutoroutePart.Absolute && !await IsAbsolutePathUniqueAsync(path, contentItem.ContentItemId)) { path = await GenerateUniqueAbsolutePathAsync(path, contentItem.ContentItemId); containedAutoroutePart.Path = path; containedAutoroutePart.Apply(); // Merge because we have disconnected the content item from it's json owner. jItem.Merge(contentItem.Content, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Replace, MergeNullValueHandling = MergeNullValueHandling.Merge }); } else { var currentItemBasePath = basePath.EndsWith('/') ? basePath : basePath + '/'; path = currentItemBasePath + containedAutoroutePart.Path; if (!IsRelativePathUnique(entries, path, containedAutoroutePart)) { path = GenerateRelativeUniquePath(entries, path, containedAutoroutePart); // Remove base path and update part path. containedAutoroutePart.Path = path.Substring(currentItemBasePath.Length); containedAutoroutePart.Apply(); // Merge because we have disconnected the content item from it's json owner. jItem.Merge(contentItem.Content, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Replace, MergeNullValueHandling = MergeNullValueHandling.Merge }); } path = path.Substring(currentItemBasePath.Length); } var containedItemBasePath = (basePath.EndsWith('/') ? basePath : basePath + '/') + path; var childItemAspect = await _contentManager.PopulateAspectAsync <ContainedContentItemsAspect>(contentItem); await ValidateContainedContentItemRoutes(entries, containerContentItemId, childItemAspect, jItem, containedItemBasePath); } } } }
private async Task PopulateContainedContentItemRoutesAsync(List <AutorouteEntry> entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JObject content, string basePath) { foreach (var accessor in containedContentItemsAspect.Accessors) { var jItems = accessor.Invoke(content); foreach (JObject jItem in jItems) { var contentItem = jItem.ToObject <ContentItem>(); var handlerAspect = await _contentManager.PopulateAspectAsync <RouteHandlerAspect>(contentItem); if (!handlerAspect.Disabled) { var path = handlerAspect.Path; if (!handlerAspect.Absolute) { path = (basePath.EndsWith('/') ? basePath : basePath + '/') + handlerAspect.Path; } entries.Add(new AutorouteEntry(containerContentItemId, path, contentItem.ContentItemId, jItem.Path)); } var itemBasePath = (basePath.EndsWith('/') ? basePath : basePath + '/') + handlerAspect.Path; var childrenAspect = await _contentManager.PopulateAspectAsync <ContainedContentItemsAspect>(contentItem); await PopulateContainedContentItemRoutesAsync(entries, containerContentItemId, childrenAspect, jItem, itemBasePath); } } }
private async Task PopulateContainedContentItemRoutes(List <AutorouteEntry> entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JObject content, string basePath, bool setHomepage = false) { foreach (var accessor in containedContentItemsAspect.Accessors) { var jItems = accessor.Invoke(content); foreach (JObject jItem in jItems) { var contentItem = jItem.ToObject <ContentItem>(); var handlerAspect = await _contentManager.PopulateAspectAsync <RouteHandlerAspect>(contentItem); if (!handlerAspect.Disabled) { var path = handlerAspect.Path; if (!handlerAspect.Absolute) { path = (basePath.EndsWith('/') ? basePath : basePath + '/') + handlerAspect.Path; } entries.Add(new AutorouteEntry(containerContentItemId, path, contentItem.ContentItemId, jItem.Path)); // Only an autoroute part, not a default handler aspect can set itself as the homepage. var autoroutePart = contentItem.As <AutoroutePart>(); if (setHomepage && autoroutePart != null && autoroutePart.SetHomepage) { await SetHomeRoute(autoroutePart, homeRoute => { homeRoute[_options.ContentItemIdKey] = containerContentItemId; homeRoute[_options.JsonPathKey] = jItem.Path; }); } } var itemBasePath = (basePath.EndsWith('/') ? basePath : basePath + '/') + handlerAspect.Path; var childrenAspect = await _contentManager.PopulateAspectAsync <ContainedContentItemsAspect>(contentItem); await PopulateContainedContentItemRoutes(entries, containerContentItemId, childrenAspect, jItem, itemBasePath); } } }
private async Task CheckContainedHomeRouteAsync(string containerContentItemId, ContainedContentItemsAspect containedAspect, JObject content) { foreach (var accessor in containedAspect.Accessors) { var jItems = accessor.Invoke(content); foreach (JObject jItem in jItems) { var contentItem = jItem.ToObject <ContentItem>(); var handlerAspect = await _contentManager.PopulateAspectAsync <RouteHandlerAspect>(contentItem); if (!handlerAspect.Disabled) { // Only an autoroute part, not a default handler aspect can set itself as the homepage. var autoroutePart = contentItem.As <AutoroutePart>(); if (autoroutePart != null && autoroutePart.SetHomepage) { await SetHomeRouteAsync(autoroutePart, homeRoute => { homeRoute[_options.ContentItemIdKey] = containerContentItemId; homeRoute[_options.JsonPathKey] = jItem.Path; }); break; } } } } }