Skip to content

Commit d3733e8

Browse files
committed
React to code review
1 parent e0cf53f commit d3733e8

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ContainedPartContentItemTypeInitializer.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@ public ContainedPartContentItemTypeInitializer(IStringLocalizer<ContainedPartCon
1818

1919
public void Initialize(ContentItemType contentItemType, ISchema schema)
2020
{
21-
// Get all types with a list part that can contain the current type.
22-
var parentTypes = schema.AdditionalTypeInstances
23-
.Where(t => t.Metadata.TryGetValue(nameof(ListPartSettings.ContainedContentTypes), out var containedTypes) && ((containedTypes as IEnumerable<string>)?.Any(ct => ct == contentItemType.Name) ?? false));
24-
25-
foreach (var parentType in parentTypes)
21+
foreach (var type in schema.AdditionalTypeInstances)
2622
{
23+
// Get all types with a list part that can contain the current type.
24+
if (!type.Metadata.TryGetValue(nameof(ListPartSettings.ContainedContentTypes), out var containedTypes))
25+
{
26+
continue;
27+
}
28+
29+
if ((containedTypes as IEnumerable<string>)?.Any(ct => ct == contentItemType.Name) != true)
30+
{
31+
continue;
32+
}
33+
2734
var fieldType = schema.AdditionalTypeInstances.FirstOrDefault(t => t is ContainedQueryObjectType);
2835

2936
if (fieldType == null)
@@ -32,8 +39,8 @@ public void Initialize(ContentItemType contentItemType, ISchema schema)
3239
schema.RegisterType(fieldType);
3340
}
3441

35-
contentItemType.Field<ContainedQueryObjectType>(parentType.Name.ToFieldName())
36-
.Description(S["The parent content item of type {0}.", parentType.Name])
42+
contentItemType.Field<ContainedQueryObjectType>(type.Name.ToFieldName())
43+
.Description(S["The parent content item of type {0}.", type.Name])
3744
.Type(fieldType)
3845
.Resolve(context =>
3946
{

src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ContainedPartContentTypeBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void Build(ISchema schema, FieldType contentQuery, ContentTypeDefinition
1717
continue;
1818
}
1919

20-
if (contentItemType.Metadata.TryGetValue("ContainedContentTypes", out var containedContentTypes) &&
20+
if (contentItemType.Metadata.TryGetValue(nameof(ListPartSettings.ContainedContentTypes), out var containedContentTypes) &&
2121
containedContentTypes is IEnumerable<string> existingContainedContentTypes)
2222
{
2323
contentItemType.Metadata[nameof(ListPartSettings.ContainedContentTypes)] = existingContainedContentTypes.Concat(settings.ContainedContentTypes).Distinct().ToArray();

0 commit comments

Comments
 (0)