Expose content type key on ContentTypeSort
This commit is contained in:
@@ -21,16 +21,18 @@ public class ContentTypeSort : IValueObject, IDeepCloneable
|
||||
SortOrder = sortOrder;
|
||||
}
|
||||
|
||||
public ContentTypeSort(Lazy<int> id, int sortOrder, string alias)
|
||||
public ContentTypeSort(Lazy<int> id, int sortOrder, string alias, Guid key)
|
||||
{
|
||||
Id = id;
|
||||
SortOrder = sortOrder;
|
||||
Alias = alias;
|
||||
Key = key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the ContentType
|
||||
/// </summary>
|
||||
// FIXME: remove this in favor of Key (Id should only be used at repository level)
|
||||
public Lazy<int> Id { get; set; } = new(() => 0);
|
||||
|
||||
/// <summary>
|
||||
@@ -43,6 +45,11 @@ public class ContentTypeSort : IValueObject, IDeepCloneable
|
||||
/// </summary>
|
||||
public string Alias { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the unique Key of the ContentType
|
||||
/// </summary>
|
||||
public Guid Key { get; set; }
|
||||
|
||||
public object DeepClone()
|
||||
{
|
||||
var clone = (ContentTypeSort)MemberwiseClone();
|
||||
|
||||
@@ -129,6 +129,7 @@ public class EntityMapDefinition : IMapDefinition
|
||||
private static void Map(EntityBasic source, ContentTypeSort target, MapperContext context)
|
||||
{
|
||||
target.Alias = source.Alias;
|
||||
target.Key = source.Key;
|
||||
target.Id = new Lazy<int>(() => Convert.ToInt32(source.Id));
|
||||
}
|
||||
|
||||
|
||||
@@ -1177,7 +1177,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
|
||||
}
|
||||
|
||||
allowedChildren?.Add(new ContentTypeSort(new Lazy<int>(() => allowedChild.Id), sortOrder,
|
||||
allowedChild.Alias));
|
||||
allowedChild.Alias, allowedChild.Key));
|
||||
sortOrder++;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ internal class ContentTypeCommonRepository : IContentTypeCommonRepository
|
||||
// prepare
|
||||
// note: same alias could be used for media, content... but always different ids = ok
|
||||
var aliases = contentTypeDtos.ToDictionary(x => x.NodeId, x => x.Alias);
|
||||
var keys = contentTypeDtos.ToDictionary(x => x.NodeId, x => x.NodeDto.UniqueId);
|
||||
|
||||
// create
|
||||
var allowedDtoIx = 0;
|
||||
@@ -120,14 +121,17 @@ internal class ContentTypeCommonRepository : IContentTypeCommonRepository
|
||||
while (allowedDtoIx < allowedDtos?.Count && allowedDtos[allowedDtoIx].Id == contentTypeDto.NodeId)
|
||||
{
|
||||
ContentTypeAllowedContentTypeDto allowedDto = allowedDtos[allowedDtoIx];
|
||||
if (!aliases.TryGetValue(allowedDto.AllowedId, out var alias))
|
||||
if (!aliases.TryGetValue(allowedDto.AllowedId, out var alias)
|
||||
|| !keys.TryGetValue(allowedDto.AllowedId, out Guid key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
allowedContentTypes.Add(new ContentTypeSort(
|
||||
new Lazy<int>(() => allowedDto.AllowedId),
|
||||
allowedDto.SortOrder, alias!));
|
||||
allowedDto.SortOrder,
|
||||
alias!,
|
||||
key));
|
||||
allowedDtoIx++;
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ public class LoadTestController : Controller
|
||||
};
|
||||
containerType.AllowedContentTypes = containerType.AllowedContentTypes.Union(new[]
|
||||
{
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType.Id), 0, contentType.Alias)
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType.Id), 0, contentType.Alias, contentType.Key)
|
||||
});
|
||||
containerType.AllowedTemplates = containerType.AllowedTemplates.Union(new[] { containerTemplate });
|
||||
containerType.SetDefaultTemplate(containerTemplate);
|
||||
|
||||
@@ -51,7 +51,8 @@ public class ContentTypeSortBuilder
|
||||
var id = _id ?? 1;
|
||||
var alias = _alias ?? Guid.NewGuid().ToString().ToCamelCase();
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
var key = Guid.NewGuid();
|
||||
|
||||
return new ContentTypeSort(new Lazy<int>(() => id), sortOrder, alias);
|
||||
return new ContentTypeSort(new Lazy<int>(() => id), sortOrder, alias, key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -809,8 +809,8 @@ public class ContentTypeRepositoryTest : UmbracoIntegrationTest
|
||||
var contentType = repository.Get(_simpleContentType.Id);
|
||||
contentType.AllowedContentTypes = new List<ContentTypeSort>
|
||||
{
|
||||
new(new Lazy<int>(() => subpageContentType.Id), 0, subpageContentType.Alias),
|
||||
new(new Lazy<int>(() => simpleSubpageContentType.Id), 1, simpleSubpageContentType.Alias)
|
||||
new(new Lazy<int>(() => subpageContentType.Id), 0, subpageContentType.Alias, subpageContentType.Key),
|
||||
new(new Lazy<int>(() => simpleSubpageContentType.Id), 1, simpleSubpageContentType.Alias, simpleSubpageContentType.Key)
|
||||
};
|
||||
repository.Save(contentType);
|
||||
|
||||
|
||||
@@ -70,18 +70,18 @@ public class ContentServicePerformanceTest : UmbracoIntegrationTest
|
||||
ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 });
|
||||
contentType1.AllowedContentTypes = new[]
|
||||
{
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType2.Id), 0, contentType2.Alias),
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType3.Id), 1, contentType3.Alias)
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType2.Id), 0, contentType2.Alias, contentType2.Key),
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType3.Id), 1, contentType3.Alias, contentType3.Key)
|
||||
};
|
||||
contentType2.AllowedContentTypes = new[]
|
||||
{
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType1.Id), 0, contentType1.Alias),
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType3.Id), 1, contentType3.Alias)
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType1.Id), 0, contentType1.Alias, contentType1.Key),
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType3.Id), 1, contentType3.Alias, contentType3.Key)
|
||||
};
|
||||
contentType3.AllowedContentTypes = new[]
|
||||
{
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType1.Id), 0, contentType1.Alias),
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType2.Id), 1, contentType2.Alias)
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType1.Id), 0, contentType1.Alias, contentType1.Key),
|
||||
new ContentTypeSort(new Lazy<int>(() => contentType2.Id), 1, contentType2.Alias, contentType2.Key)
|
||||
};
|
||||
ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 });
|
||||
|
||||
|
||||
@@ -652,7 +652,7 @@ public class ContentServiceTagsTests : UmbracoIntegrationTest
|
||||
CreateAndAddTagsPropertyType(contentType);
|
||||
ContentTypeService.Save(contentType);
|
||||
contentType.AllowedContentTypes =
|
||||
new[] { new ContentTypeSort(new Lazy<int>(() => contentType.Id), 0, contentType.Alias) };
|
||||
new[] { new ContentTypeSort(new Lazy<int>(() => contentType.Id), 0, contentType.Alias, contentType.Key) };
|
||||
|
||||
var content = ContentBuilder.CreateSimpleContent(contentType, "Tagged content");
|
||||
content.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags",
|
||||
|
||||
@@ -1843,7 +1843,7 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent
|
||||
ContentTypeBuilder.CreateSimpleContentType("umbTextpage1", "Textpage", defaultTemplateId: template.Id);
|
||||
contentType.AllowedContentTypes = new List<ContentTypeSort>
|
||||
{
|
||||
new(new Lazy<int>(() => contentType.Id), 0, contentType.Alias)
|
||||
new(new Lazy<int>(() => contentType.Id), 0, contentType.Alias, contentType.Key)
|
||||
};
|
||||
ContentTypeService.Save(contentType);
|
||||
|
||||
@@ -1883,7 +1883,7 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent
|
||||
ContentTypeBuilder.CreateSimpleContentType("umbTextpage1", "Textpage", defaultTemplateId: template.Id);
|
||||
contentType.AllowedContentTypes = new List<ContentTypeSort>
|
||||
{
|
||||
new(new Lazy<int>(() => contentType.Id), 0, contentType.Alias)
|
||||
new(new Lazy<int>(() => contentType.Id), 0, contentType.Alias, contentType.Key)
|
||||
};
|
||||
ContentTypeService.Save(contentType);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user