Created
February 27, 2024 09:32
-
-
Save trnktms/0dbdbffd31c923726d7b7cf817074bcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExtendedApiContentResponseBuilder : LayoutBuilderBase<IApiContentResponse>, IApiContentResponseBuilder | |
{ | |
private readonly IApiContentRouteBuilder _apiContentRouteBuilder; | |
public ExtendedApiContentResponseBuilder( | |
IApiContentNameProvider apiContentNameProvider, | |
IApiContentRouteBuilder apiContentRouteBuilder, | |
IOutputExpansionStrategyAccessor outputExpansionStrategyAccessor, | |
IEnumerable<IComponentResolver> componentResolvers, | |
IApiPublishedContentCache apiPublishedContentCache) | |
: base(apiContentNameProvider, apiContentRouteBuilder, outputExpansionStrategyAccessor, componentResolvers, apiPublishedContentCache) | |
{ | |
_apiContentRouteBuilder = apiContentRouteBuilder; | |
} | |
protected override IApiContentResponse Create(IPublishedContent content, string name, IApiContentRoute route, IDictionary<string, object?> properties) | |
{ | |
var cultures = GetCultures(content); | |
return new ApiContentResponse( | |
content.Key, | |
name, | |
content.ContentType.Alias, | |
content.CreateDate, | |
content.UpdateDate, | |
route, | |
properties, | |
cultures); | |
} | |
/// <summary> | |
/// Copied from the original ApiContentResponseBuilder | |
/// </summary> | |
private Dictionary<string, IApiContentRoute> GetCultures(IPublishedContent content) | |
{ | |
var routesByCulture = new Dictionary<string, IApiContentRoute>(); | |
foreach (var publishedCultureInfo in content.Cultures.Values) | |
{ | |
if (publishedCultureInfo.Culture.IsNullOrWhiteSpace()) | |
{ | |
continue; | |
} | |
var cultureRoute = _apiContentRouteBuilder.Build(content, publishedCultureInfo.Culture); | |
if (cultureRoute == null) | |
{ | |
continue; | |
} | |
routesByCulture[publishedCultureInfo.Culture] = cultureRoute; | |
} | |
return routesByCulture; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment