Class EntityController
- Namespace
- Umbraco.Cms.Web.BackOffice.Controllers
- Assembly
- Umbraco.Web.BackOffice.dll
The API controller used for getting entity objects, basic name, icon, id representation of umbraco objects that are based on CMSNode
public class EntityController : UmbracoAuthorizedJsonController
- Inheritance
-
EntityController
- Inherited Members
Remarks
This controller allows resolving basic entity data for various entities without placing the hard restrictions on users that may not have access to the sections these entities entities exist in. This is to allow pickers, etc... of data to work for all users. In some cases such as accessing Members, more explicit security checks are done.
Some objects such as macros are not based on CMSNode
Constructors
EntityController(ITreeService, UmbracoTreeSearcher, SearchableTreeCollection, IPublishedContentQuery, IShortStringHelper, IEntityService, IBackOfficeSecurityAccessor, IPublishedUrlProvider, IContentService, IUmbracoMapper, IDataTypeService, ISqlContext, ILocalizedTextService, IFileService, IContentTypeService, IMediaTypeService, IMacroService, IUserService, ILocalizationService, AppCaches)
[Obsolete("Use non-obsolete ctor. This will be removed in Umbraco 14.")]
public EntityController(ITreeService treeService, UmbracoTreeSearcher treeSearcher, SearchableTreeCollection searchableTreeCollection, IPublishedContentQuery publishedContentQuery, IShortStringHelper shortStringHelper, IEntityService entityService, IBackOfficeSecurityAccessor backofficeSecurityAccessor, IPublishedUrlProvider publishedUrlProvider, IContentService contentService, IUmbracoMapper umbracoMapper, IDataTypeService dataTypeService, ISqlContext sqlContext, ILocalizedTextService localizedTextService, IFileService fileService, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMacroService macroService, IUserService userService, ILocalizationService localizationService, AppCaches appCaches)
Parameters
treeServiceITreeServicetreeSearcherUmbracoTreeSearchersearchableTreeCollectionSearchableTreeCollectionpublishedContentQueryIPublishedContentQueryshortStringHelperIShortStringHelperentityServiceIEntityServicebackofficeSecurityAccessorIBackOfficeSecurityAccessorpublishedUrlProviderIPublishedUrlProvidercontentServiceIContentServiceumbracoMapperIUmbracoMapperdataTypeServiceIDataTypeServicesqlContextISqlContextlocalizedTextServiceILocalizedTextServicefileServiceIFileServicecontentTypeServiceIContentTypeServicemediaTypeServiceIMediaTypeServicemacroServiceIMacroServiceuserServiceIUserServicelocalizationServiceILocalizationServiceappCachesAppCaches
EntityController(ITreeService, UmbracoTreeSearcher, SearchableTreeCollection, IPublishedContentQuery, IShortStringHelper, IEntityService, IBackOfficeSecurityAccessor, IPublishedUrlProvider, IContentService, IUmbracoMapper, IDataTypeService, ISqlContext, ILocalizedTextService, IFileService, IContentTypeService, IMediaTypeService, IMacroService, IUserService, ILocalizationService, AppCaches, IDynamicRootService, IVariationContextAccessor)
[ActivatorUtilitiesConstructor]
public EntityController(ITreeService treeService, UmbracoTreeSearcher treeSearcher, SearchableTreeCollection searchableTreeCollection, IPublishedContentQuery publishedContentQuery, IShortStringHelper shortStringHelper, IEntityService entityService, IBackOfficeSecurityAccessor backofficeSecurityAccessor, IPublishedUrlProvider publishedUrlProvider, IContentService contentService, IUmbracoMapper umbracoMapper, IDataTypeService dataTypeService, ISqlContext sqlContext, ILocalizedTextService localizedTextService, IFileService fileService, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMacroService macroService, IUserService userService, ILocalizationService localizationService, AppCaches appCaches, IDynamicRootService dynamicRootService, IVariationContextAccessor variationContextAccessor)
Parameters
treeServiceITreeServicetreeSearcherUmbracoTreeSearchersearchableTreeCollectionSearchableTreeCollectionpublishedContentQueryIPublishedContentQueryshortStringHelperIShortStringHelperentityServiceIEntityServicebackofficeSecurityAccessorIBackOfficeSecurityAccessorpublishedUrlProviderIPublishedUrlProvidercontentServiceIContentServiceumbracoMapperIUmbracoMapperdataTypeServiceIDataTypeServicesqlContextISqlContextlocalizedTextServiceILocalizedTextServicefileServiceIFileServicecontentTypeServiceIContentTypeServicemediaTypeServiceIMediaTypeServicemacroServiceIMacroServiceuserServiceIUserServicelocalizationServiceILocalizationServiceappCachesAppCachesdynamicRootServiceIDynamicRootServicevariationContextAccessorIVariationContextAccessor
Methods
GetAll(UmbracoEntityTypes, string)
public IEnumerable<EntityBasic>? GetAll(UmbracoEntityTypes type, string postFilter)
Parameters
typeUmbracoEntityTypesThe type of entity.
postFilterstringOptional filter - Format like: "BoolVariable==true&IntVariable>=6". Invalid filters are ignored.
Returns
- IEnumerable<EntityBasic>
GetAncestors(Guid, UmbracoEntityTypes, FormCollection)
public ActionResult<IEnumerable<EntityBasic>> GetAncestors(Guid id, UmbracoEntityTypes type, FormCollection queryStrings)
Parameters
idGuidtypeUmbracoEntityTypesqueryStringsFormCollection
Returns
- ActionResult<IEnumerable<EntityBasic>>
GetAncestors(int, UmbracoEntityTypes, FormCollection)
public IEnumerable<EntityBasic> GetAncestors(int id, UmbracoEntityTypes type, FormCollection queryStrings)
Parameters
idinttypeUmbracoEntityTypesqueryStringsFormCollection
Returns
- IEnumerable<EntityBasic>
GetAnchors(AnchorsModel)
[HttpGet]
[HttpPost]
public IEnumerable<string> GetAnchors(AnchorsModel model)
Parameters
modelAnchorsModel
Returns
GetById(Guid, UmbracoEntityTypes)
Gets an entity by it's key
public ActionResult<EntityBasic?> GetById(Guid id, UmbracoEntityTypes type)
Parameters
idGuidtypeUmbracoEntityTypes
Returns
- ActionResult<EntityBasic>
GetById(int, UmbracoEntityTypes)
Gets an entity by it's id
public ActionResult<EntityBasic?> GetById(int id, UmbracoEntityTypes type)
Parameters
idinttypeUmbracoEntityTypes
Returns
- ActionResult<EntityBasic>
GetById(Udi, UmbracoEntityTypes)
Gets an entity by it's UDI
public ActionResult<EntityBasic?> GetById(Udi id, UmbracoEntityTypes type)
Parameters
idUditypeUmbracoEntityTypes
Returns
- ActionResult<EntityBasic>
GetByIds(Guid[], UmbracoEntityTypes)
Get entities by GUID ids
[HttpGet]
[HttpPost]
public ActionResult<IEnumerable<EntityBasic>> GetByIds(Guid[] ids, UmbracoEntityTypes type)
Parameters
idsGuid[]typeUmbracoEntityTypes
Returns
- ActionResult<IEnumerable<EntityBasic>>
Remarks
We allow for POST because there could be quite a lot of Ids
GetByIds(int[], UmbracoEntityTypes)
Get entities by integer ids
[HttpGet]
[HttpPost]
public ActionResult<IEnumerable<EntityBasic>> GetByIds(int[] ids, UmbracoEntityTypes type)
Parameters
idsint[]typeUmbracoEntityTypes
Returns
- ActionResult<IEnumerable<EntityBasic>>
Remarks
We allow for POST because there could be quite a lot of Ids
GetByIds(Udi[], UmbracoEntityTypes)
Get entities by UDIs
[HttpGet]
[HttpPost]
public ActionResult<IEnumerable<EntityBasic>> GetByIds(Udi[] ids, UmbracoEntityTypes type)
Parameters
idsUdi[]A list of UDIs to lookup items by, all UDIs must be of the same UDI type!
typeUmbracoEntityTypes
Returns
- ActionResult<IEnumerable<EntityBasic>>
Remarks
We allow for POST because there could be quite a lot of Ids.
GetByQuery(string, int, UmbracoEntityTypes)
Gets an entity by a xpath query - OBSOLETE
[Obsolete("This will be removed in Umbraco 13. Use GetByXPath instead")]
public ActionResult<EntityBasic?>? GetByQuery(string query, int nodeContextId, UmbracoEntityTypes type)
Parameters
Returns
- ActionResult<EntityBasic>
GetByXPath(string, int, int?, UmbracoEntityTypes)
Gets an entity by a xpath query
[Obsolete("The current implementation of this method is suboptimal and will be removed entirely in a future version. Scheduled for removal in v14")]
public ActionResult<EntityBasic?>? GetByXPath(string query, int nodeContextId, int? parentId, UmbracoEntityTypes type)
Parameters
Returns
- ActionResult<EntityBasic>
GetChildren(int, UmbracoEntityTypes, Guid?)
public IEnumerable<EntityBasic> GetChildren(int id, UmbracoEntityTypes type, Guid? dataTypeKey = null)
Parameters
Returns
- IEnumerable<EntityBasic>
GetDynamicRootAsync(DynamicRootViewModel)
[HttpPost]
public Task<ActionResult<EntityBasic?>> GetDynamicRootAsync(EntityController.DynamicRootViewModel model)
Parameters
Returns
- Task<ActionResult<EntityBasic>>
GetPagedChildren(int, UmbracoEntityTypes, int, int, string, Direction, string, Guid?)
Get paged child entities by id
public ActionResult<PagedResult<EntityBasic>> GetPagedChildren(int id, UmbracoEntityTypes type, int pageNumber, int pageSize, string orderBy = "SortOrder", Direction orderDirection = 0, string filter = "", Guid? dataTypeKey = null)
Parameters
idinttypeUmbracoEntityTypespageNumberintpageSizeintorderBystringorderDirectionDirectionfilterstringdataTypeKeyGuid?
Returns
- ActionResult<PagedResult<EntityBasic>>
GetPagedChildren(string, UmbracoEntityTypes, int, int, string, Direction, string, Guid?)
Get paged child entities by id
public ActionResult<PagedResult<EntityBasic>> GetPagedChildren(string id, UmbracoEntityTypes type, int pageNumber, int pageSize, string orderBy = "SortOrder", Direction orderDirection = 0, string filter = "", Guid? dataTypeKey = null)
Parameters
idstringtypeUmbracoEntityTypespageNumberintpageSizeintorderBystringorderDirectionDirectionfilterstringdataTypeKeyGuid?
Returns
- ActionResult<PagedResult<EntityBasic>>
GetPagedDescendants(int, UmbracoEntityTypes, int, int, string, Direction, string, Guid?)
public ActionResult<PagedResult<EntityBasic>> GetPagedDescendants(int id, UmbracoEntityTypes type, int pageNumber, int pageSize, string orderBy = "SortOrder", Direction orderDirection = 0, string filter = "", Guid? dataTypeKey = null)
Parameters
idinttypeUmbracoEntityTypespageNumberintpageSizeintorderBystringorderDirectionDirectionfilterstringdataTypeKeyGuid?
Returns
- ActionResult<PagedResult<EntityBasic>>
GetPath(Guid, UmbracoEntityTypes)
Gets the path for a given node ID
public IConvertToActionResult GetPath(Guid id, UmbracoEntityTypes type)
Parameters
idGuidtypeUmbracoEntityTypes
Returns
GetPath(int, UmbracoEntityTypes)
Gets the path for a given node ID
public IConvertToActionResult GetPath(int id, UmbracoEntityTypes type)
Parameters
idinttypeUmbracoEntityTypes
Returns
GetPath(Udi, UmbracoEntityTypes)
Gets the path for a given node ID
public IActionResult GetPath(Udi id, UmbracoEntityTypes type)
Parameters
idUditypeUmbracoEntityTypes
Returns
GetSafeAlias(string, bool)
Returns an Umbraco alias given a string
public dynamic GetSafeAlias(string value, bool camelCase = true)
Parameters
Returns
- dynamic
GetUrl(int, UmbracoEntityTypes, string?)
Gets the URL of an entity
public IActionResult GetUrl(int id, UmbracoEntityTypes type, string? culture = null)
Parameters
idintInt id of the entity to fetch URL for
typeUmbracoEntityTypesThe type of entity such as Document, Media, Member
culturestringThe culture to fetch the URL for
Returns
- IActionResult
The URL or path to the item
Remarks
We are not restricting this with security because there is no sensitive data
GetUrl(Udi, string)
Gets the URL of an entity
public IActionResult GetUrl(Udi id, string culture = "*")
Parameters
idUdiUDI of the entity to fetch URL for
culturestringThe culture to fetch the URL for
Returns
- IActionResult
The URL or path to the item
GetUrlAndAnchors(int, string?)
[HttpGet]
public UrlAndAnchors GetUrlAndAnchors(int id, string? culture = "*")
Parameters
Returns
- UrlAndAnchors
GetUrlAndAnchors(Udi, string)
[HttpGet]
public ActionResult<UrlAndAnchors> GetUrlAndAnchors(Udi id, string culture = "*")
Parameters
idUdiculturestring
Returns
- ActionResult<UrlAndAnchors>
GetUrlsByIds(Guid[], UmbracoEntityTypes, string?)
Get entity URLs by IDs
[HttpGet]
[HttpPost]
public IDictionary<Guid, string?> GetUrlsByIds(Guid[] ids, UmbracoEntityTypes type, string? culture = null)
Parameters
idsGuid[]A list of IDs to lookup items by
typeUmbracoEntityTypesThe entity type to look for.
culturestringThe culture to fetch the URL for.
Returns
- IDictionary<Guid, string>
Dictionary mapping Udi -> Url
Remarks
We allow for POST because there could be quite a lot of Ids.
GetUrlsByIds(int[], UmbracoEntityTypes, string?)
Get entity URLs by IDs
[HttpGet]
[HttpPost]
public IDictionary<int, string?> GetUrlsByIds(int[] ids, UmbracoEntityTypes type, string? culture = null)
Parameters
idsint[]A list of IDs to lookup items by
typeUmbracoEntityTypesThe entity type to look for.
culturestringThe culture to fetch the URL for.
Returns
- IDictionary<int, string>
Dictionary mapping Udi -> Url
Remarks
We allow for POST because there could be quite a lot of Ids.
GetUrlsByIds(Udi[], UmbracoEntityTypes, string?)
Get entity URLs by IDs
[HttpGet]
[HttpPost]
public IDictionary<Udi, string?> GetUrlsByIds(Udi[] ids, UmbracoEntityTypes type, string? culture = null)
Parameters
idsUdi[]A list of IDs to lookup items by
typeUmbracoEntityTypesThe entity type to look for.
culturestringThe culture to fetch the URL for.
Returns
- IDictionary<Udi, string>
Dictionary mapping Udi -> Url
Remarks
We allow for POST because there could be quite a lot of Ids.
Search(string, UmbracoEntityTypes, string?, Guid?)
Searches for results based on the entity type
[HttpGet]
public IEnumerable<EntityBasic> Search(string query, UmbracoEntityTypes type, string? searchFrom = null, Guid? dataTypeKey = null)
Parameters
querystringtypeUmbracoEntityTypessearchFromstringA starting point for the search, generally a node id, but for members this is a member type alias
dataTypeKeyGuid?If set used to look up whether user and group start node permissions will be ignored.
Returns
- IEnumerable<EntityBasic>
SearchAll(string)
Searches for all content that the user is allowed to see (based on their allowed sections)
[HttpGet]
public Task<IDictionary<string, TreeSearchResult>> SearchAll(string query)
Parameters
querystring
Returns
- Task<IDictionary<string, TreeSearchResult>>
Remarks
Even though a normal entity search will allow any user to search on a entity type that they may not have access to edit, we need to filter these results to the sections they are allowed to edit since this search function is explicitly for the global search so if we showed entities that they weren't allowed to edit they would get errors when clicking on the result. The reason a user is allowed to search individual entity types that they are not allowed to edit is because those search methods might be used in things like pickers in the content editor.