-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 122 introduce subpages element + bump nuget * 122 introduce ManagementElementHelper * 122 introduce ElementTypeHelper * 122 subpages impl * 122 little refactoring * 122 little refactoring * 122 add missing test case
- Loading branch information
Showing
12 changed files
with
311 additions
and
186 deletions.
There are no files selected for viewing
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
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
64 changes: 0 additions & 64 deletions
64
src/Kentico.Kontent.ModelGenerator.Core/Helpers/ElementIdHelper.cs
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
src/Kentico.Kontent.ModelGenerator.Core/Helpers/ElementTypeHelper.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,45 @@ | ||
using System; | ||
using Kentico.Kontent.Management.Models.Types.Elements; | ||
using Kentico.Kontent.ModelGenerator.Core.Common; | ||
using Kentico.Kontent.ModelGenerator.Core.Configuration; | ||
|
||
namespace Kentico.Kontent.ModelGenerator.Core.Helpers | ||
{ | ||
public static class ElementTypeHelper | ||
{ | ||
public static string GetElementType(CodeGeneratorOptions options, string elementType, ElementMetadataBase managementElement) | ||
{ | ||
Validate(options, elementType, managementElement); | ||
|
||
if (options.ContentManagementApi && elementType == "modular_content" && managementElement.Type == ElementMetadataType.Subpages) | ||
{ | ||
return "subpages"; | ||
} | ||
|
||
if (options.StructuredModel && Property.IsContentTypeSupported(elementType + Property.StructuredSuffix, options.ContentManagementApi)) | ||
{ | ||
elementType += Property.StructuredSuffix; | ||
} | ||
|
||
return elementType; | ||
} | ||
|
||
private static void Validate(CodeGeneratorOptions options, string elementType, ElementMetadataBase managementElement) | ||
{ | ||
if (options == null) | ||
{ | ||
throw new ArgumentNullException(nameof(options)); | ||
} | ||
|
||
if (elementType == null) | ||
{ | ||
throw new ArgumentNullException(nameof(elementType)); | ||
} | ||
|
||
if (options.ContentManagementApi && managementElement == null) | ||
{ | ||
throw new ArgumentNullException(nameof(managementElement)); | ||
} | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/Kentico.Kontent.ModelGenerator.Core/Helpers/ManagementElementHelper.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,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Kentico.Kontent.Delivery.Abstractions; | ||
using Kentico.Kontent.Management.Models.Types; | ||
using Kentico.Kontent.Management.Models.Types.Elements; | ||
using Kentico.Kontent.Management.Models.TypeSnippets; | ||
|
||
namespace Kentico.Kontent.ModelGenerator.Core.Helpers | ||
{ | ||
public static class ManagementElementHelper | ||
{ | ||
public static ElementMetadataBase GetManagementElement( | ||
bool cmApi, | ||
IContentElement deliverElement, | ||
IEnumerable<ContentTypeSnippetModel> managementSnippets, | ||
ContentTypeModel managementContentType) | ||
{ | ||
if (!cmApi) | ||
{ | ||
return null; | ||
} | ||
|
||
Validate(deliverElement, managementSnippets, managementContentType); | ||
|
||
var managementContentTypeElement = managementContentType.Elements.FirstOrDefault(el => el.Codename == deliverElement.Codename); | ||
if (managementContentTypeElement != null) | ||
{ | ||
return managementContentTypeElement; | ||
} | ||
|
||
var managementSnippet = managementSnippets.FirstOrDefault(s => | ||
managementContentType.Elements.FirstOrDefault(el => | ||
el.Type == ElementMetadataType.ContentTypeSnippet && el.Codename == s.Codename) != null); | ||
if (managementSnippet == null) | ||
{ | ||
throw new ArgumentException($"{nameof(managementSnippet)} shouldn't be null."); | ||
} | ||
|
||
var managementSnippetElement = managementSnippet.Elements.FirstOrDefault(el => el.Codename == deliverElement.Codename); | ||
if (managementSnippetElement == null) | ||
{ | ||
throw new ArgumentException($"{nameof(managementSnippetElement)} shouldn't be null."); | ||
} | ||
|
||
return managementSnippetElement; | ||
} | ||
|
||
private static void Validate( | ||
IContentElement deliverElement, | ||
IEnumerable<ContentTypeSnippetModel> managementSnippets, | ||
ContentTypeModel managementContentType) | ||
{ | ||
if (deliverElement == null) | ||
{ | ||
throw new ArgumentNullException(nameof(deliverElement)); | ||
} | ||
|
||
if (managementSnippets == null) | ||
{ | ||
throw new ArgumentNullException(nameof(managementSnippets)); | ||
} | ||
|
||
if (managementContentType == null) | ||
{ | ||
throw new ArgumentNullException(nameof(managementContentType)); | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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.