Updated management API endpoint and model for data type references to align with that used for documents, media etc. (#18905)

* Updated management API endpoint and model for data type references to align with that used for documents, media etc.

* Refactoring.

* Update src/Umbraco.Core/Constants-ReferenceTypes.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fixed typos.

* Added id to tracked reference content type response.

* Updated OpenApi.json.

* Added missing updates.

* Renamed model and constants from code review feedback.

* Fix typo

* Fix multiple enumeration

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: mole <nikolajlauridsen@protonmail.ch>
This commit is contained in:
Andy Butland
2025-04-04 15:10:06 +02:00
committed by GitHub
parent fd77074d57
commit 1f4c19d484
21 changed files with 591 additions and 8 deletions

View File

@@ -139,6 +139,7 @@ public class MediaTypeBuilder
var mediaType = builder
.WithAlias(alias)
.WithName(name)
.WithIcon("icon-picture")
.WithParentContentType(parent)
.AddPropertyGroup()
.WithAlias(propertyGroupAlias)

View File

@@ -30,6 +30,8 @@ public class DataTypeServiceTests : UmbracoIntegrationTest
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
private IMediaTypeService MediaTypeService => GetRequiredService<IMediaTypeService>();
private IFileService FileService => GetRequiredService<IFileService>();
private IConfigurationEditorJsonSerializer ConfigurationEditorJsonSerializer =>
@@ -446,4 +448,43 @@ public class DataTypeServiceTests : UmbracoIntegrationTest
Assert.IsFalse(result.Success);
Assert.AreEqual(DataTypeOperationStatus.NonDeletable, result.Status);
}
[Test]
public async Task DataTypeService_Can_Get_References()
{
IEnumerable<IDataType> dataTypeDefinitions = await DataTypeService.GetByEditorAliasAsync(Constants.PropertyEditors.Aliases.RichText);
IContentType documentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Text Page");
ContentTypeService.Save(documentType);
IMediaType mediaType = MediaTypeBuilder.CreateSimpleMediaType("umbMediaItem", "Media Item");
MediaTypeService.Save(mediaType);
documentType = ContentTypeService.Get(documentType.Id);
Assert.IsNotNull(documentType.PropertyTypes.SingleOrDefault(pt => pt.PropertyEditorAlias is Constants.PropertyEditors.Aliases.RichText));
mediaType = MediaTypeService.Get(mediaType.Id);
Assert.IsNotNull(mediaType.PropertyTypes.SingleOrDefault(pt => pt.PropertyEditorAlias is Constants.PropertyEditors.Aliases.RichText));
var definition = dataTypeDefinitions.First();
var definitionKey = definition.Key;
PagedModel<RelationItemModel> result = await DataTypeService.GetPagedRelationsAsync(definitionKey, 0, 10);
Assert.AreEqual(2, result.Total);
RelationItemModel firstResult = result.Items.First();
Assert.AreEqual("umbTextpage", firstResult.ContentTypeAlias);
Assert.AreEqual("Text Page", firstResult.ContentTypeName);
Assert.AreEqual("icon-document", firstResult.ContentTypeIcon);
Assert.AreEqual(documentType.Key, firstResult.ContentTypeKey);
Assert.AreEqual("bodyText", firstResult.NodeAlias);
Assert.AreEqual("Body text", firstResult.NodeName);
RelationItemModel secondResult = result.Items.Skip(1).First();
Assert.AreEqual("umbMediaItem", secondResult.ContentTypeAlias);
Assert.AreEqual("Media Item", secondResult.ContentTypeName);
Assert.AreEqual("icon-picture", secondResult.ContentTypeIcon);
Assert.AreEqual(mediaType.Key, secondResult.ContentTypeKey);
Assert.AreEqual("bodyText", secondResult.NodeAlias);
Assert.AreEqual("Body text", secondResult.NodeName);
}
}