public static string FindAlias(UmbracoObjectTypes objectType, int id) { var item = UmbracoContext.Current.Application.Services.EntityService.Get(id, objectType); object alias = null; item.AdditionalData.TryGetValue("Alias", out alias); return alias as string; }
public string GetPathFromId(int id, UmbracoObjectTypes type) { var item = _entityService.Get(id, type); if (item != null && !item.Trashed) return GetPath(item); return string.Empty; }
private static void AddEnableRelations(MenuRenderingEventArgs eventArgs, UmbracoObjectTypes objectType, UrlHelper urlHelper) { if (objectType == UmbracoObjectTypes.DocumentType || objectType == UmbracoObjectTypes.MediaType) { var menuItem = eventArgs.Menu.Items.Add<EnableRelationsAction>("Enable relations"); menuItem.LaunchDialogView(urlHelper.Content("~/App_Plugins/RelationEditor/enablerelations.html"), "Enable relations"); } }
/// <summary> /// Returns the available composite content types for a given content type /// </summary> /// <param name="type"></param> /// <param name="filterContentTypes"> /// This is normally an empty list but if additional content type aliases are passed in, any content types containing those aliases will be filtered out /// along with any content types that have matching property types that are included in the filtered content types /// </param> /// <param name="filterPropertyTypes"> /// This is normally an empty list but if additional property type aliases are passed in, any content types that have these aliases will be filtered out. /// This is required because in the case of creating/modifying a content type because new property types being added to it are not yet persisted so cannot /// be looked up via the db, they need to be passed in. /// </param> /// <param name="contentTypeId"></param> /// <param name="isElement">Whether the composite content types should be applicable for an element type</param> /// <returns></returns> protected IEnumerable <Tuple <EntityBasic, bool> > PerformGetAvailableCompositeContentTypes(int contentTypeId, UmbracoObjectTypes type, string[] filterContentTypes, string[] filterPropertyTypes, bool isElement) { IContentTypeComposition source = null; //below is all ported from the old doc type editor and comes with the same weaknesses /insanity / magic IContentTypeComposition[] allContentTypes; switch (type) { case UmbracoObjectTypes.DocumentType: if (contentTypeId > 0) { source = Services.ContentTypeService.Get(contentTypeId); if (source == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } } allContentTypes = Services.ContentTypeService.GetAll().Cast <IContentTypeComposition>().ToArray(); break; case UmbracoObjectTypes.MediaType: if (contentTypeId > 0) { source = Services.MediaTypeService.Get(contentTypeId); if (source == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } } allContentTypes = Services.MediaTypeService.GetAll().Cast <IContentTypeComposition>().ToArray(); break; case UmbracoObjectTypes.MemberType: if (contentTypeId > 0) { source = Services.MemberTypeService.Get(contentTypeId); if (source == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } } allContentTypes = Services.MemberTypeService.GetAll().Cast <IContentTypeComposition>().ToArray(); break; default: throw new ArgumentOutOfRangeException("The entity type was not a content type"); } var availableCompositions = Services.ContentTypeService.GetAvailableCompositeContentTypes(source, allContentTypes, filterContentTypes, filterPropertyTypes, isElement); var currCompositions = source == null ? new IContentTypeComposition[] { } : source.ContentTypeComposition.ToArray(); var compAliases = currCompositions.Select(x => x.Alias).ToArray(); var ancestors = availableCompositions.Ancestors.Select(x => x.Alias); return(availableCompositions.Results .Select(x => new Tuple <EntityBasic, bool>(Mapper.Map <IContentTypeComposition, EntityBasic>(x.Composition), x.Allowed)) .Select(x => { //we need to ensure that the item is enabled if it is already selected // but do not allow it if it is any of the ancestors if (compAliases.Contains(x.Item1.Alias) && ancestors.Contains(x.Item1.Alias) == false) { //re-set x to be allowed (NOTE: I didn't know you could set an enumerable item in a lambda!) x = new Tuple <EntityBasic, bool>(x.Item1, true); } //translate the name x.Item1.Name = TranslateItem(x.Item1.Name); var contentType = allContentTypes.FirstOrDefault(c => c.Key == x.Item1.Key); var containers = GetEntityContainers(contentType, type)?.ToArray(); var containerPath = $"/{(containers != null && containers.Any() ? $"{string.Join("/", containers.Select(c => c.Name))}/" : null)}"; x.Item1.AdditionalData["containerPath"] = containerPath; return x; }) .ToList()); }
/// <summary> /// Returns a list of content types where a particular composition content type is used /// </summary> /// <param name="type">Type of content Type, eg documentType or mediaType</param> /// <param name="contentTypeId">Id of composition content type</param> /// <returns></returns> protected IEnumerable <EntityBasic> PerformGetWhereCompositionIsUsedInContentTypes(int contentTypeId, UmbracoObjectTypes type) { var id = 0; if (contentTypeId > 0) { IContentTypeComposition source; switch (type) { case UmbracoObjectTypes.DocumentType: source = Services.ContentTypeService.Get(contentTypeId); break; case UmbracoObjectTypes.MediaType: source = Services.MediaTypeService.Get(contentTypeId); break; case UmbracoObjectTypes.MemberType: source = Services.MemberTypeService.Get(contentTypeId); break; default: throw new ArgumentOutOfRangeException(nameof(type)); } if (source == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } id = source.Id; } IEnumerable <IContentTypeComposition> composedOf; switch (type) { case UmbracoObjectTypes.DocumentType: composedOf = Services.ContentTypeService.GetComposedOf(id); break; case UmbracoObjectTypes.MediaType: composedOf = Services.MediaTypeService.GetComposedOf(id); break; case UmbracoObjectTypes.MemberType: composedOf = Services.MemberTypeService.GetComposedOf(id); break; default: throw new ArgumentOutOfRangeException(nameof(type)); } EntityBasic TranslateName(EntityBasic e) { e.Name = TranslateItem(e.Name); return(e); } return(composedOf .Select(Mapper.Map <IContentTypeComposition, EntityBasic>) .Select(TranslateName) .ToList()); }
/// <inheritdoc/> public override object Map(IPublishedContent content, object value) { if (value == null) { return(Enumerable.Empty <object>()); } // Single IPublishedContent if (value is IPublishedContent published) { return(published); } // ReSharper disable once PossibleNullReferenceException Type type = value.GetType(); // Multiple IPublishedContent if (type.IsEnumerableOfType(typeof(IPublishedContent))) { return((IEnumerable <IPublishedContent>)value); } int[] nodeIds = Empty; // First try enumerable strings, ints. if (type.IsGenericType || type.IsArray) { if (type.IsEnumerableOfType(typeof(string))) { int n; nodeIds = ((IEnumerable <string>)value) .Select(x => int.TryParse(x, NumberStyles.Any, this.Culture, out n) ? n : -1) .ToArray(); } if (type.IsEnumerableOfType(typeof(int))) { nodeIds = ((IEnumerable <int>)value).ToArray(); } } // Now csv strings. if (!nodeIds.Any()) { string s = value as string ?? value.ToString(); if (!string.IsNullOrWhiteSpace(s)) { int n; nodeIds = XmlHelper.CouldItBeXml(s) ? s.GetXmlIds() : s.ToDelimitedList() .Select(x => int.TryParse(x, NumberStyles.Any, this.Culture, out n) ? n : -1) .Where(x => x > 0) .ToArray(); } } if (nodeIds.Any()) { UmbracoObjectTypes objectType = UmbracoObjectTypes.Unknown; var multiPicker = new List <IPublishedContent>(); // Oh so ugly if you let Resharper do this. // ReSharper disable once LoopCanBeConvertedToQuery foreach (int nodeId in nodeIds) { IPublishedContent item = this.GetPublishedContent(nodeId, ref objectType, UmbracoObjectTypes.Document, this.UmbracoContext.ContentCache.GetById) ?? this.GetPublishedContent(nodeId, ref objectType, UmbracoObjectTypes.Media, this.UmbracoContext.MediaCache.GetById) ?? this.GetPublishedContent(nodeId, ref objectType, UmbracoObjectTypes.Member, this.Members.GetById); if (item != null) { multiPicker.Add(item); } } return(multiPicker); } return(this.DefaultValue); }
public ObjectTypeConfiguration Get(UmbracoObjectTypes objectType, string alias) { return ObjectTypes .FirstOrDefault(t => t.Name == objectType && t.Alias == alias) ?? new ObjectTypeConfiguration(); }
public uSyncTreeWalker(UmbracoObjectTypes type) { _entityService = ApplicationContext.Current.Services.EntityService; _type = type; }
/// <summary> /// Returns the GUID for a given integer id /// </summary> /// <param name="id"></param> /// <param name="umbracoObjectType"></param> /// <returns></returns> public Attempt <Guid> GetKeyForId(int id, UmbracoObjectTypes umbracoObjectType) { return(_idkMap.GetKeyForId(id, umbracoObjectType)); }
private static void AddEditRelations(MenuRenderingEventArgs eventArgs, UmbracoObjectTypes type, string alias, UrlHelper urlHelper) { var typeConfig = Configuration.Get(type, alias); if (!typeConfig.Enabled || !typeConfig.EnabledRelations.Any()) return; var menuItem = eventArgs.Menu.Items.Add<EditRelationsAction>("Edit relations"); menuItem.LaunchDialogView( urlHelper.Content("~/App_Plugins/RelationEditor/editrelations.html"), "Edit relations" ); }
internal static int[] CombineStartNodes(UmbracoObjectTypes objectType, int[] groupSn, int[] userSn, IEntityService entityService) { // assume groupSn and userSn each don't contain duplicates var asn = groupSn.Concat(userSn).Distinct().ToArray(); var paths = asn.Length > 0 ? entityService.GetAllPaths(objectType, asn).ToDictionary(x => x.Id, x => x.Path) : new Dictionary <int, string>(); paths[Constants.System.Root] = Constants.System.RootString; // entityService does not get that one var binPath = GetBinPath(objectType); var lsn = new List <int>(); foreach (var sn in groupSn) { if (paths.TryGetValue(sn, out var snp) == false) { continue; // ignore rogue node (no path) } if (StartsWithPath(snp, binPath)) { continue; // ignore bin } if (lsn.Any(x => StartsWithPath(snp, paths[x]))) { continue; // skip if something above this sn } lsn.RemoveAll(x => StartsWithPath(paths[x], snp)); // remove anything below this sn lsn.Add(sn); } var usn = new List <int>(); foreach (var sn in userSn) { if (paths.TryGetValue(sn, out var snp) == false) { continue; // ignore rogue node (no path) } if (StartsWithPath(snp, binPath)) { continue; // ignore bin } if (usn.Any(x => StartsWithPath(paths[x], snp))) { continue; // skip if something below this sn } usn.RemoveAll(x => StartsWithPath(snp, paths[x])); // remove anything above this sn usn.Add(sn); } foreach (var sn in usn) { var snp = paths[sn]; // has to be here now lsn.RemoveAll(x => StartsWithPath(snp, paths[x]) || StartsWithPath(paths[x], snp)); // remove anything above or below this sn lsn.Add(sn); } return(lsn.ToArray()); }
/// <summary> /// Gets the name corresponding to this Umbraco object type. /// </summary> public static string?GetName(this UmbracoObjectTypes objectType) { return(Enum.GetName(typeof(UmbracoObjectTypes), objectType)); }
/// <summary> /// Returns a list of content types where a particular composition content type is used /// </summary> /// <param name="type">Type of content Type, eg documentType or mediaType</param> /// <param name="contentTypeId">Id of composition content type</param> /// <returns></returns> protected ActionResult <IEnumerable <EntityBasic> > PerformGetWhereCompositionIsUsedInContentTypes( int contentTypeId, UmbracoObjectTypes type) { var id = 0; if (contentTypeId > 0) { IContentTypeComposition?source; switch (type) { case UmbracoObjectTypes.DocumentType: source = ContentTypeService.Get(contentTypeId); break; case UmbracoObjectTypes.MediaType: source = MediaTypeService.Get(contentTypeId); break; case UmbracoObjectTypes.MemberType: source = MemberTypeService.Get(contentTypeId); break; default: throw new ArgumentOutOfRangeException(nameof(type)); } if (source == null) { return(NotFound()); } id = source.Id; } IEnumerable <IContentTypeComposition> composedOf; switch (type) { case UmbracoObjectTypes.DocumentType: composedOf = ContentTypeService.GetComposedOf(id); break; case UmbracoObjectTypes.MediaType: composedOf = MediaTypeService.GetComposedOf(id); break; case UmbracoObjectTypes.MemberType: composedOf = MemberTypeService.GetComposedOf(id); break; default: throw new ArgumentOutOfRangeException(nameof(type)); } EntityBasic TranslateName(EntityBasic e) { e.Name = TranslateItem(e.Name); return(e); } return(composedOf .Select(UmbracoMapper.Map <IContentTypeComposition, EntityBasic>) .WhereNotNull() .Select(TranslateName) .ToList()); }
public TypedId(T id, UmbracoObjectTypes umbracoObjectType) { UmbracoObjectType = umbracoObjectType; Id = id; }
/// <summary> /// Returns a paged collection of descendants. /// </summary> public IEnumerable <IUmbracoEntity> GetPagedDescendants(IEnumerable <int> ids, UmbracoObjectTypes umbracoObjectType, long pageIndex, int pageSize, out long totalRecords, string orderBy = "path", Direction orderDirection = Direction.Ascending, string filter = "") { totalRecords = 0; var idsA = ids.ToArray(); if (idsA.Length == 0) { return(Enumerable.Empty <IUmbracoEntity>()); } var objectTypeId = umbracoObjectType.GetGuid(); using (var uow = UowProvider.GetUnitOfWork(readOnly: true)) { var repository = RepositoryFactory.CreateEntityRepository(uow); var query = Query <IUmbracoEntity> .Builder; if (idsA.All(x => x != Constants.System.Root)) { //lookup the paths so we can use it in the prefix query below var itemPaths = repository.GetAllPaths(objectTypeId, idsA).ToArray(); if (itemPaths.Length == 0) { totalRecords = 0; return(Enumerable.Empty <IUmbracoEntity>()); } var clauses = new List <Expression <Func <IUmbracoEntity, bool> > >(); foreach (var id in idsA) { //if the id is root then don't add any clauses if (id != Constants.System.Root) { var itemPath = itemPaths.FirstOrDefault(x => x.Id == id); if (itemPath == null) { continue; } var path = itemPath.Path; var qid = id; clauses.Add(x => x.Path.SqlStartsWith(string.Format("{0},", path), TextColumnType.NVarchar) || x.Path.SqlEndsWith(string.Format(",{0}", qid), TextColumnType.NVarchar)); } } query.WhereAny(clauses); } IQuery <IUmbracoEntity> filterQuery = null; if (filter.IsNullOrWhiteSpace() == false) { filterQuery = Query <IUmbracoEntity> .Builder.Where(x => x.Name.Contains(filter)); } var contents = repository.GetPagedResultsByQuery(query, objectTypeId, pageIndex, pageSize, out totalRecords, orderBy, orderDirection, filterQuery); return(contents); } }
/// <summary> /// Returns the integer id for a given GUID /// </summary> /// <param name="key"></param> /// <param name="umbracoObjectType"></param> /// <returns></returns> public Attempt <int> GetIdForKey(Guid key, UmbracoObjectTypes umbracoObjectType) { return(_idkMap.GetIdForKey(key, umbracoObjectType)); }
/// <summary> /// Attempt to get an IPublishedContent instance based on ID and content type /// </summary> /// <param name="nodeId">The content node ID</param> /// <param name="actualType">The type of content being requested</param> /// <param name="expectedType">The type of content expected/supported by <paramref name="contentFetcher"/></param> /// <param name="contentFetcher">A function to fetch content of type <paramref name="expectedType"/></param> /// <returns>The requested content, or null if either it does not exist or <paramref name="actualType"/> does not match <paramref name="expectedType"/></returns> private IPublishedContent GetPublishedContent <T>(T nodeId, ref UmbracoObjectTypes actualType, UmbracoObjectTypes expectedType, Func <T, IPublishedContent> contentFetcher) { // is the actual type supported by the content fetcher? if (actualType != UmbracoObjectTypes.Unknown && actualType != expectedType) { // no, return null return(null); } // attempt to get the content var content = contentFetcher(nodeId); if (content != null) { // if we found the content, assign the expected type to the actual type so we don't have to keep looking for other types of content actualType = expectedType; } return(content); }
/// <summary> /// Attempt to get an <see cref="IPublishedContent"/> instance based on id and object type. /// </summary> /// <param name="nodeId">The content node ID</param> /// <param name="actual">The type of content being requested</param> /// <param name="expected">The type of content expected/supported by <paramref name="typedMethod"/></param> /// <param name="typedMethod">A function to fetch content of type <paramref name="expected"/></param> /// <returns> /// The requested content, or null if either it does not exist or <paramref name="actual"/> does not /// match <paramref name="expected"/> /// </returns> private IPublishedContent GetPublishedContent(int nodeId, ref UmbracoObjectTypes actual, UmbracoObjectTypes expected, Func <int, IPublishedContent> typedMethod) { // Is the given type supported by the typed method. if (actual != UmbracoObjectTypes.Unknown && actual != expected) { return(null); } // Attempt to get the content IPublishedContent content = typedMethod(nodeId); if (content != null) { // If we find the content, assign the expected type to the actual type so we don't have to // keep looking for other types of content. actual = expected; } return(content); }
public SyncContainerSerializerBase(IEntityService entityService, ILogger logger, UmbracoObjectTypes containerType) : base(entityService, logger) { this.containerType = containerType; }
/// <summary> /// Attempt to get an <see cref="IPublishedContent"/> instance based on id and object type. /// </summary> /// <param name="nodeId">The content node ID</param> /// <param name="actual">The type of content being requested</param> /// <param name="expected">The type of content expected/supported by <paramref name="typedMethod"/></param> /// <param name="typedMethod">A function to fetch content of type <paramref name="expected"/></param> /// <returns> /// The requested content, or null if either it does not exist or <paramref name="actual"/> does not /// match <paramref name="expected"/> /// </returns> private IPublishedContent GetPublishedContent(int nodeId, ref UmbracoObjectTypes actual, UmbracoObjectTypes expected, Func<int, IPublishedContent> typedMethod) { // Is the given type supported by the typed method. if (actual != UmbracoObjectTypes.Unknown && actual != expected) { return null; } // Attempt to get the content var content = typedMethod(nodeId); if (content != null) { // If we find the content, assign the expected type to the actual type so we don't have to // keep looking for other types of content. actual = expected; } return content; }
public static string FromUmbracoObjectType(UmbracoObjectTypes umbracoObjectType) { switch (umbracoObjectType) { case UmbracoObjectTypes.Document: return(Document); case UmbracoObjectTypes.DocumentBlueprint: return(DocumentBlueprint); case UmbracoObjectTypes.Media: return(Media); case UmbracoObjectTypes.Member: return(Member); case UmbracoObjectTypes.Template: return(Template); case UmbracoObjectTypes.DocumentType: return(DocumentType); case UmbracoObjectTypes.DocumentTypeContainer: return(DocumentTypeContainer); case UmbracoObjectTypes.MediaType: return(MediaType); case UmbracoObjectTypes.MediaTypeContainer: return(MediaTypeContainer); case UmbracoObjectTypes.DataType: return(DataType); case UmbracoObjectTypes.DataTypeContainer: return(DataTypeContainer); case UmbracoObjectTypes.MemberType: return(MemberType); case UmbracoObjectTypes.MemberGroup: return(MemberGroup); case UmbracoObjectTypes.Stylesheet: return(Stylesheet); case UmbracoObjectTypes.RelationType: return(RelationType); case UmbracoObjectTypes.FormsForm: return(FormsForm); case UmbracoObjectTypes.FormsPreValue: return(FormsPreValue); case UmbracoObjectTypes.FormsDataSource: return(FormsDataSource); case UmbracoObjectTypes.Language: return(Language); } throw new NotSupportedException(string.Format("UmbracoObjectType \"{0}\" does not have a matching EntityType.", umbracoObjectType)); }
public static void Set(UmbracoObjectTypes objectType, string alias, ObjectTypeConfiguration typeConfiguration) { lock (LockObj) { var existing = ObjectTypes.FirstOrDefault(t => t.Name == objectType && t.Alias == alias); if (existing != null) configuration.ObjectTypes.Remove(existing); if (typeConfiguration.EnabledRelations.Any()) { typeConfiguration.Alias = alias; typeConfiguration.Name = objectType; configuration.ObjectTypes.Add(typeConfiguration); } Save(); } }
public TypedId(T id, UmbracoObjectTypes umbracoObjectType) { _umbracoObjectType = umbracoObjectType; _id = id; }
/// <summary> /// Attempt to get an IPublishedContent instance based on ID and content type /// </summary> /// <param name="nodeId">The content node ID</param> /// <param name="actualType">The type of content being requested</param> /// <param name="expectedType">The type of content expected/supported by <paramref name="contentFetcher"/></param> /// <param name="contentFetcher">A function to fetch content of type <paramref name="expectedType"/></param> /// <returns>The requested content, or null if either it does not exist or <paramref name="actualType"/> does not match <paramref name="expectedType"/></returns> private IPublishedContent GetPublishedContent(int nodeId, ref UmbracoObjectTypes actualType, UmbracoObjectTypes expectedType, Func<int, IPublishedContent> contentFetcher) { // is the actual type supported by the content fetcher? if (actualType != UmbracoObjectTypes.Unknown && actualType != expectedType) { // no, return null return null; } // attempt to get the content var content = contentFetcher(nodeId); if (content != null) { // if we found the content, assign the expected type to the actual type so we don't have to keep looking for other types of content actualType = expectedType; } return content; }
private IEnumerable <EntityContainer> GetEntityContainers(IContentTypeComposition contentType, UmbracoObjectTypes type) { if (contentType == null) { return(null); } switch (type) { case UmbracoObjectTypes.DocumentType: return(Services.ContentTypeService.GetContainers(contentType as IContentType)); case UmbracoObjectTypes.MediaType: return(Services.MediaTypeService.GetContainers(contentType as IMediaType)); case UmbracoObjectTypes.MemberType: return(new EntityContainer[0]); default: throw new ArgumentOutOfRangeException("The entity type was not a content type"); } }