1- using System ;
2- using System . Collections . Generic ;
31using System . Data ;
4- using System . Linq ;
52using System . Net . Mime ;
63using System . Text ;
74using Microsoft . AspNetCore . Authorization ;
85using Microsoft . AspNetCore . Mvc ;
96using Microsoft . Extensions . DependencyInjection ;
107using Microsoft . Extensions . Options ;
11- using NPoco ;
128using Umbraco . Cms . Core ;
139using Umbraco . Cms . Core . Configuration . Models ;
1410using Umbraco . Cms . Core . DependencyInjection ;
1511using Umbraco . Cms . Core . Mapping ;
1612using Umbraco . Cms . Core . Models ;
1713using Umbraco . Cms . Core . Models . ContentEditing ;
14+ using Umbraco . Cms . Core . Models . Entities ;
1815using Umbraco . Cms . Core . PropertyEditors ;
1916using Umbraco . Cms . Core . Security ;
2017using Umbraco . Cms . Core . Serialization ;
@@ -37,6 +34,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
3734 [ PluginController ( Constants . Web . Mvc . BackOfficeApiArea ) ]
3835 [ Authorize ( Policy = AuthorizationPolicies . TreeAccessDocumentsOrDocumentTypes ) ]
3936 [ ParameterSwapControllerActionSelector ( nameof ( GetById ) , "id" , typeof ( int ) , typeof ( Guid ) , typeof ( Udi ) ) ]
37+ [ ParameterSwapControllerActionSelector ( nameof ( GetReferences ) , "id" , typeof ( int ) , typeof ( Guid ) ) ]
4038 public class DataTypeController : BackOfficeNotificationsController
4139 {
4240 private readonly PropertyEditorCollection _propertyEditors ;
@@ -51,6 +49,7 @@ public class DataTypeController : BackOfficeNotificationsController
5149 private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor ;
5250 private readonly IConfigurationEditorJsonSerializer _serializer ;
5351 private readonly IDataTypeUsageService _dataTypeUsageService ;
52+ private readonly IIdKeyMap _idKeyMap ;
5453
5554 [ Obsolete ( "Use constructor that takes IDataTypeUsageService, scheduled for removal in V12" ) ]
5655 public DataTypeController (
@@ -77,11 +76,12 @@ public DataTypeController(
7776 localizedTextService ,
7877 backOfficeSecurityAccessor ,
7978 serializer ,
80- StaticServiceProvider . Instance . GetRequiredService < IDataTypeUsageService > ( ) )
79+ StaticServiceProvider . Instance . GetRequiredService < IDataTypeUsageService > ( ) ,
80+ StaticServiceProvider . Instance . GetRequiredService < IIdKeyMap > ( ) )
8181 {
8282 }
8383
84- [ ActivatorUtilitiesConstructor ]
84+ [ Obsolete ( "Use constructor that takes IDataTypeUsageService, scheduled for removal in V17" ) ]
8585 public DataTypeController (
8686 PropertyEditorCollection propertyEditors ,
8787 IDataTypeService dataTypeService ,
@@ -95,6 +95,38 @@ public DataTypeController(
9595 IBackOfficeSecurityAccessor backOfficeSecurityAccessor ,
9696 IConfigurationEditorJsonSerializer serializer ,
9797 IDataTypeUsageService dataTypeUsageService )
98+ : this (
99+ propertyEditors ,
100+ dataTypeService ,
101+ contentSettings ,
102+ umbracoMapper ,
103+ propertyEditorCollection ,
104+ contentTypeService ,
105+ mediaTypeService ,
106+ memberTypeService ,
107+ localizedTextService ,
108+ backOfficeSecurityAccessor ,
109+ serializer ,
110+ dataTypeUsageService ,
111+ StaticServiceProvider . Instance . GetRequiredService < IIdKeyMap > ( ) )
112+ {
113+ }
114+
115+ [ ActivatorUtilitiesConstructor ]
116+ public DataTypeController (
117+ PropertyEditorCollection propertyEditors ,
118+ IDataTypeService dataTypeService ,
119+ IOptionsSnapshot < ContentSettings > contentSettings ,
120+ IUmbracoMapper umbracoMapper ,
121+ PropertyEditorCollection propertyEditorCollection ,
122+ IContentTypeService contentTypeService ,
123+ IMediaTypeService mediaTypeService ,
124+ IMemberTypeService memberTypeService ,
125+ ILocalizedTextService localizedTextService ,
126+ IBackOfficeSecurityAccessor backOfficeSecurityAccessor ,
127+ IConfigurationEditorJsonSerializer serializer ,
128+ IDataTypeUsageService dataTypeUsageService ,
129+ IIdKeyMap entityService )
98130 {
99131 _propertyEditors = propertyEditors ?? throw new ArgumentNullException ( nameof ( propertyEditors ) ) ;
100132 _dataTypeService = dataTypeService ?? throw new ArgumentNullException ( nameof ( dataTypeService ) ) ;
@@ -108,6 +140,7 @@ public DataTypeController(
108140 _backOfficeSecurityAccessor = backOfficeSecurityAccessor ?? throw new ArgumentNullException ( nameof ( backOfficeSecurityAccessor ) ) ;
109141 _serializer = serializer ?? throw new ArgumentNullException ( nameof ( serializer ) ) ;
110142 _dataTypeUsageService = dataTypeUsageService ?? throw new ArgumentNullException ( nameof ( dataTypeUsageService ) ) ;
143+ _idKeyMap = entityService ?? throw new ArgumentNullException ( nameof ( entityService ) ) ;
111144 }
112145
113146 /// <summary>
@@ -421,10 +454,10 @@ public IActionResult PostRenameContainer(int id, string name)
421454 }
422455
423456 /// <summary>
424- /// Returns the references (usages) for the data type
457+ /// Returns the references (usages) for the data type.
425458 /// </summary>
426- /// <param name="id"></param>
427- /// <returns></returns>
459+ /// <param name="id">Data type's integer Id. </param>
460+ [ HttpGet ]
428461 public DataTypeReferences GetReferences ( int id )
429462 {
430463 var result = new DataTypeReferences ( ) ;
@@ -462,6 +495,19 @@ public DataTypeReferences GetReferences(int id)
462495 return result ;
463496 }
464497
498+ /// <summary>
499+ /// Returns the references (usages) for the data type.
500+ /// </summary>
501+ /// <param name="id">Data type's key.</param>
502+ [ HttpGet ]
503+ public DataTypeReferences GetReferences ( Guid id )
504+ {
505+ Attempt < int > dataType = _idKeyMap . GetIdForKey ( id , UmbracoObjectTypes . DataType ) ;
506+ return dataType . Success
507+ ? GetReferences ( dataType . Result )
508+ : new DataTypeReferences ( ) ;
509+ }
510+
465511 [ HttpGet ]
466512 public ActionResult < DataTypeHasValuesDisplay > HasValues ( int id )
467513 {
0 commit comments