-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0965bf
commit 804b6b1
Showing
17 changed files
with
1,392 additions
and
756 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
backend/src/Squidex.Domain.Apps.Core.Operations/ConvertContent/AddSchemaNames.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// ========================================================================== | ||
// Squidex Headless CMS | ||
// ========================================================================== | ||
// Copyright (c) Squidex UG (haftungsbeschraenkt) | ||
// All rights reserved. Licensed under the MIT license. | ||
// ========================================================================== | ||
|
||
using Squidex.Domain.Apps.Core.Contents; | ||
using Squidex.Domain.Apps.Core.Schemas; | ||
using Squidex.Infrastructure; | ||
using Squidex.Infrastructure.Json.Objects; | ||
|
||
namespace Squidex.Domain.Apps.Core.ConvertContent | ||
{ | ||
public sealed class AddSchemaNames : IContentItemConverter | ||
{ | ||
private readonly ResolvedComponents components; | ||
|
||
public AddSchemaNames(ResolvedComponents components) | ||
{ | ||
this.components = components; | ||
} | ||
|
||
public JsonObject ConvertItem(IField field, JsonObject source) | ||
{ | ||
if (field is IArrayField) | ||
{ | ||
return source; | ||
} | ||
|
||
if (source.ContainsKey("schemaName")) | ||
{ | ||
return source; | ||
} | ||
|
||
if (!Component.IsValid(source, out var discriminator)) | ||
{ | ||
return source; | ||
} | ||
|
||
var id = DomainId.Create(discriminator); | ||
|
||
if (components.TryGetValue(id, out var schema)) | ||
{ | ||
source["schemaName"] = schema.Name; | ||
} | ||
|
||
return source; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.