Skip to content

Commit 70ed6a9

Browse files
authored
Throw an exception when part is not found (#18310)
1 parent dd395f2 commit 70ed6a9

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

src/OrchardCore.Modules/OrchardCore.ContentFields/Handlers/TextFieldHandler.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,8 @@ private async Task SetValueAsync(ContentFieldContextBase context, TextField fiel
7070
field.Text = value?.Trim();
7171

7272
var partActivator = _contentPartFactory.GetTypeActivator(context.PartName);
73-
var part = field.ContentItem.Get(partActivator.Type, context.ContentPartFieldDefinition.ContentTypePartDefinition.Name) as ContentPart;
74-
75-
if (part == null)
76-
{
77-
part = partActivator.CreateInstance();
78-
field.ContentItem.Weld(context.ContentPartFieldDefinition.ContentTypePartDefinition.Name, part);
79-
}
73+
var part = (field.ContentItem.Get(partActivator.Type, context.ContentPartFieldDefinition.ContentTypePartDefinition.Name) as ContentPart)
74+
?? throw new InvalidOperationException($"The content part '{context.ContentPartFieldDefinition.ContentTypePartDefinition.Name}' could not be found.");
8075

8176
part.Apply(context.ContentPartFieldDefinition.Name, field);
8277
}

0 commit comments

Comments
 (0)