public IEnumerable <string> Resolve(IContentTypeComposition source) { var aliases = new List <string>(); // get ancestor ids from path of parent if not root if (source.ParentId != Constants.System.Root) { var parent = _contentTypeService.Get(source.ParentId); if (parent != null) { var ancestorIds = parent.Path.Split(',').Select(int.Parse); // loop through all content types and return ordered aliases of ancestors var allContentTypes = _contentTypeService.GetAll().ToArray(); foreach (var ancestorId in ancestorIds) { var ancestor = allContentTypes.FirstOrDefault(x => x.Id == ancestorId); if (ancestor != null) { aliases.Add(ancestor.Alias); } } } } return(aliases.OrderBy(x => x)); }
private IEnumerable <string> MapLockedCompositions(IContentTypeComposition source) { // get ancestor ids from path of parent if not root if (source.ParentId == Constants.System.Root) { return(Enumerable.Empty <string>()); } IContentType?parent = _contentTypeService.Get(source.ParentId); if (parent == null) { return(Enumerable.Empty <string>()); } var aliases = new List <string>(); IEnumerable <int>?ancestorIds = parent.Path?.Split(Constants.CharArrays.Comma) .Select(s => int.Parse(s, CultureInfo.InvariantCulture)); // loop through all content types and return ordered aliases of ancestors IContentType[] allContentTypes = _contentTypeService.GetAll().ToArray(); if (ancestorIds is not null) { foreach (var ancestorId in ancestorIds) { IContentType?ancestor = allContentTypes.FirstOrDefault(x => x.Id == ancestorId); if (ancestor is not null && ancestor.Alias is not null) { aliases.Add(ancestor.Alias); } } } return(aliases.OrderBy(x => x)); }
public async Task <PurgeResponse> PurgeAsync(IEnumerable <IPublishedContent> content) { var config = _configService.GetConfig(); var publishedContent = content as IPublishedContent[] ?? content.ToArray(); var contentTypeIds = publishedContent.Select(c => c.ContentType.Id).ToHashSet().ToArray(); var contentTypes = _contentTypeService.GetAll(contentTypeIds).ToDictionary(c => c.Id, c => c); var filteredContent = publishedContent.Where(c => config.ContentFilter.AllowedContent(contentTypes[c.ContentType.Id])); using (var context = _umbracoContextFactory.EnsureUmbracoContext()) { var urls = from contentItem in filteredContent from culture in contentItem.Cultures select context.UmbracoContext.UrlProvider.GetUrl(contentItem, UrlMode.Absolute, culture.Key); if (!urls.Any()) { return(new PurgeResponse( result: PurgeResult.NothingPurged, failedUrls: null, failMessages: null, exception: null)); } var request = new PurgeRequest(urls); return(await PurgeAsync(request)); } }
/// <summary> /// Returns the references (usages) for the data type /// </summary> /// <param name="id"></param> /// <returns></returns> public DataTypeReferences GetReferences(int id) { var result = new DataTypeReferences(); var usages = _dataTypeService.GetReferences(id); foreach (var groupOfEntityType in usages.GroupBy(x => x.Key.EntityType)) { //get all the GUIDs for the content types to find var guidsAndPropertyAliases = groupOfEntityType.ToDictionary(i => ((GuidUdi)i.Key).Guid, i => i.Value); if (groupOfEntityType.Key == ObjectTypes.GetUdiType(UmbracoObjectTypes.DocumentType)) { result.DocumentTypes = GetContentTypeUsages(_contentTypeService.GetAll(guidsAndPropertyAliases.Keys), guidsAndPropertyAliases); } else if (groupOfEntityType.Key == ObjectTypes.GetUdiType(UmbracoObjectTypes.MediaType)) { result.MediaTypes = GetContentTypeUsages(_mediaTypeService.GetAll(guidsAndPropertyAliases.Keys), guidsAndPropertyAliases); } else if (groupOfEntityType.Key == ObjectTypes.GetUdiType(UmbracoObjectTypes.MemberType)) { result.MemberTypes = GetContentTypeUsages(_memberTypeService.GetAll(guidsAndPropertyAliases.Keys), guidsAndPropertyAliases); } } return(result); }
public async Task <IViewComponentResult> InvokeAsync(short selectedContentType = 0) { var contentTypes = await _contentTypeService.GetAll().ToListAsync(); var tupleModel = new Tuple <List <ContentType>, short>(contentTypes, selectedContentType); return(View(tupleModel)); }
/// <summary> /// Gets all of the element types (e.g. content types that have been marked as an element type). /// </summary> /// <param name="contentTypeService">The content type service.</param> /// <returns>Returns all the element types.</returns> public static IEnumerable <IContentType> GetAllElementTypes(this IContentTypeService contentTypeService) { if (contentTypeService == null) { return(Enumerable.Empty <IContentType>()); } return(contentTypeService.GetAll().Where(x => x.IsElement)); }
protected override ActionResult <TreeNode?> CreateRootNode(FormCollection queryStrings) { var rootResult = base.CreateRootNode(queryStrings); if (!(rootResult.Result is null)) { return(rootResult); } var root = rootResult.Value; if (root is not null) { //check if there are any types root.HasChildren = _contentTypeService.GetAll().Any(); } return(root); }
public IList <TypeModel> GetAllTypes() { var types = new List <TypeModel>(); // TODO: this will require 3 rather large SQL queries on startup in ModelsMode.InMemoryAuto mode. I know that these will be cached after lookup but it will slow // down startup time ... BUT these queries are also used in NuCache on startup so we can't really avoid them. Maybe one day we can // load all of these in in one query and still have them cached per service, and/or somehow improve the perf of these since they are used on startup // in more than one place. types.AddRange(GetTypes( PublishedItemType.Content, _contentTypeService.GetAll().Cast <IContentTypeComposition>().ToArray())); types.AddRange(GetTypes( PublishedItemType.Media, _mediaTypeService.GetAll().Cast <IContentTypeComposition>().ToArray())); types.AddRange(GetTypes( PublishedItemType.Member, _memberTypeService.GetAll().Cast <IContentTypeComposition>().ToArray())); return(EnsureDistinctAliases(types)); }
/// <summary> /// Get method to retrieve a list of all document types. /// </summary> /// <returns>A sorted list of all document types.</returns> public object GetAllDocumentTypes() { var retval = new List <Object>(); foreach (var doctype in _contentTypeService.GetAll().OrderBy(d => d.Name)) { retval.Add(new { id = doctype.Id, alias = doctype.Alias, name = doctype.Name }); } return(retval); }
/// <summary> /// Gets a list of all content types /// </summary> /// <returns></returns> public IEnumerable <ContentTypeModel> GetContentTypes() { var contentTypes = _contentTypeService.GetAll() .Select(x => new ContentTypeModel { Alias = x.Alias, Name = _localizedTextService.Localize("template", "contentOfType", tokens: new string[] { x.Name }) }) .OrderBy(x => x.Name).ToList(); contentTypes.Insert(0, new ContentTypeModel { Alias = string.Empty, Name = _localizedTextService.Localize("template", "allContent") }); return(contentTypes); }
protected override IEnumerable <ElementTypeValidationModel> GetElementTypeValidation(object value) { var rows = _nestedContentValues.GetPropertyValues(value); if (rows.Count == 0) { yield break; } // There is no guarantee that the client will post data for every property defined in the Element Type but we still // need to validate that data for each property especially for things like 'required' data to work. // Lookup all element types for all content/settings and then we can populate any empty properties. var allElementAliases = rows.Select(x => x.ContentTypeAlias).ToList(); // unfortunately we need to get all content types and post filter - but they are cached so its ok, there's // no overload to lookup by many aliases. var allElementTypes = _contentTypeService.GetAll().Where(x => allElementAliases.Contains(x.Alias)).ToDictionary(x => x.Alias); foreach (var row in rows) { if (!allElementTypes.TryGetValue(row.ContentTypeAlias, out var elementType)) { throw new InvalidOperationException($"No element type found with alias {row.ContentTypeAlias}"); } // now ensure missing properties foreach (var elementTypeProp in elementType.CompositionPropertyTypes) { if (!row.PropertyValues.ContainsKey(elementTypeProp.Alias)) { // set values to null row.PropertyValues[elementTypeProp.Alias] = new NestedContentValues.NestedContentPropertyValue { PropertyType = elementTypeProp, Value = null }; row.RawPropertyValues[elementTypeProp.Alias] = null; } } var elementValidation = new ElementTypeValidationModel(row.ContentTypeAlias, row.Id); foreach (var prop in row.PropertyValues) { elementValidation.AddPropertyTypeValidation( new PropertyTypeValidationModel(prop.Value.PropertyType, prop.Value.Value)); } yield return(elementValidation); } }
public async Task <IViewComponentResult> InvokeAsync() { var contentTypeList = await _contentTypeService.GetAll().AsNoTracking().Select(c => c.Id).ToListAsync(); var list = new List <Domain.Content>(); contentTypeList.ForEach(id => { var result = _contentService.GetAll().AsNoTracking().Include(c => c.ContentType).Where(c => c.IsActive && c.ContentType.IsActive).Include(c => c.CoverImage).Include(p => p.ProfileImage).OrderByDescending(c => c.CreationTime).FirstOrDefault(c => c.ContentTypeId == id); if (result != null) { list.Add(result); } }); return(View(list)); }
private void TreeControllerBase_TreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs e) { switch (sender.TreeAlias) { case Constants.Trees.DocumentTypes: UpdateNodeIcons(e, _contentTypeService.GetAll()?.ToDictionary(c => c.Id, c => c.Icon), Constants.Trees.DocumentTypes); break; case Constants.Trees.MemberTypes: UpdateNodeIcons(e, _memberTypeService.GetAll()?.ToDictionary(c => c.Id, c => c.Icon), Constants.Trees.MemberTypes); break; case Constants.Trees.MediaTypes: UpdateNodeIcons(e, _mediaTypeService.GetAll()?.ToDictionary(c => c.Id, c => c.Icon), Constants.Trees.MediaTypes); break; } }
private void TreeControllerBase_TreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs e) { if (sender.TreeAlias == "documentTypes") { var contentTypes = _contentTypeService.GetAll().ToDictionary(c => c.Id); foreach (var node in e.Nodes) { if (node.NodeType == "documentTypes") { if (int.TryParse(node.Id.ToString(), out var nodeId) && nodeId > 0) { var contentType = contentTypes[nodeId]; node.Icon = contentType.Icon; } } } } }
protected override IEnumerable <ElementTypeValidationModel> GetElementTypeValidation(object?value) { BlockEditorData?blockEditorData = _blockEditorValues.DeserializeAndClean(value); if (blockEditorData != null) { // There is no guarantee that the client will post data for every property defined in the Element Type but we still // need to validate that data for each property especially for things like 'required' data to work. // Lookup all element types for all content/settings and then we can populate any empty properties. var allElements = blockEditorData.BlockValue.ContentData.Concat(blockEditorData.BlockValue.SettingsData) .ToList(); var allElementTypes = _contentTypeService.GetAll(allElements.Select(x => x.ContentTypeKey).ToArray()) .ToDictionary(x => x.Key); foreach (BlockItemData row in allElements) { if (!allElementTypes.TryGetValue(row.ContentTypeKey, out IContentType? elementType)) { throw new InvalidOperationException($"No element type found with key {row.ContentTypeKey}"); } // now ensure missing properties foreach (IPropertyType elementTypeProp in elementType.CompositionPropertyTypes) { if (!row.PropertyValues.ContainsKey(elementTypeProp.Alias)) { // set values to null row.PropertyValues[elementTypeProp.Alias] = new BlockItemData.BlockPropertyValue(null, elementTypeProp); row.RawPropertyValues[elementTypeProp.Alias] = null; } } var elementValidation = new ElementTypeValidationModel(row.ContentTypeAlias, row.Key); foreach (KeyValuePair <string, BlockItemData.BlockPropertyValue> prop in row.PropertyValues) { elementValidation.AddPropertyTypeValidation( new PropertyTypeValidationModel(prop.Value.PropertyType, prop.Value.Value)); } yield return(elementValidation); } } }
public IEnumerable <DataListItem> GetItems(Dictionary <string, object> config) { var types = config.GetValueAs("contentTypes", defaultValue: default(JArray))?.ToObject <IEnumerable <string> >(); var isDocumentTypeWithTemplate = types?.InvariantContains("documentTypesTemplates") == true; var isDocumentType = types?.InvariantContains("documentTypes") == true; var isElementType = types?.InvariantContains("elementTypes") == true; return(_contentTypeService .GetAll() .Where(x => { var result = false; if (isDocumentTypeWithTemplate == true) { result |= x.IsElement == false && x.AllowedTemplates?.Any() == true; } if (isDocumentType == true) { result |= x.IsElement == false && x.AllowedTemplates?.Any() == false; } if (isElementType == true) { result |= x.IsElement == true; } return result; }) .OrderBy(x => x.Name) .Select(x => new DataListItem { Name = x.Name, Value = Udi.Create(UmbConstants.UdiEntityType.DocumentType, x.Key).ToString(), Icon = x.Icon, Description = string.Join(", ", x.AllowedTemplates.Select(t => t.Alias)), })); }
/// <summary> /// Checks the tree alias and node alias to see if we should update the icon /// Gets the types from the type services and calls the method to update the node icons /// </summary> /// <param name="sender">Tree controller base</param> /// <param name="e">Event args</param> private void TreeControllerBase_TreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs e) { switch (sender.TreeAlias) { case "documentTypes": var contentTypeIcons = _contentTypeService.GetAll().ToDictionary(c => c.Id, c => c.Icon); UpdateNodeIcons(e, contentTypeIcons, "documentTypes"); break; case "memberTypes": var memberTypeIcons = _memberTypeService.GetAll().ToDictionary(c => c.Id, c => c.Icon); UpdateNodeIcons(e, memberTypeIcons, "memberTypes"); break; case "mediaTypes": var mediaTypeIcons = _mediaTypeService.GetAll().ToDictionary(c => c.Id, c => c.Icon); UpdateNodeIcons(e, mediaTypeIcons, "mediaTypes"); break; default: // don't change the icon break; } }
public BlockEditorValues(BlockEditorDataConverter dataConverter, IContentTypeService contentTypeService, ILogger logger) { _contentTypes = new Lazy <Dictionary <Guid, IContentType> >(() => contentTypeService.GetAll().ToDictionary(c => c.Key)); _dataConverter = dataConverter; _logger = logger; }
public NestedContentValues(IContentTypeService contentTypeService) { _contentTypes = new Lazy <Dictionary <string, IContentType> >(() => contentTypeService.GetAll().ToDictionary(c => c.Alias)); }
private void ContentService_Saving(IContentService sender, SaveEventArgs <IContent> e) { var saved = e.SavedEntities.ToList(); if (saved.Count == 0) { return; } var contentTypes = _contentTypeService.GetAll(saved.Select(x => x.ContentTypeId).ToArray()).ToDictionary(x => x.Id); foreach (var content in saved) { if (content.ContentType.Alias.InvariantEquals("ArticulateRichText") || content.ContentType.Alias.InvariantEquals("ArticulateMarkdown")) { content.SetAllPropertyCultureValues( "publishedDate", contentTypes[content.ContentTypeId], // if the publishedDate is not already set, then set it (c, ct, culture) => c.GetValue("publishedDate", culture?.Culture) == null ? (DateTime?)DateTime.Now : null); content.SetAllPropertyCultureValues( "author", contentTypes[content.ContentTypeId], // if the author is not already set, then set it (c, ct, culture) => c.GetValue("author", culture?.Culture) == null ? _umbracoContextAccessor?.UmbracoContext?.Security?.CurrentUser?.Name : null); if (!content.HasIdentity) { // default values content.SetAllPropertyCultureValues( "enableComments", contentTypes[content.ContentTypeId], (c, ct, culture) => 1); } } if (_configs.Articulate().AutoGenerateExcerpt) { if (content.ContentType.Alias.InvariantEquals("ArticulateRichText") || content.ContentType.Alias.InvariantEquals("ArticulateMarkdown")) { // fill in the excerpt if it is empty content.SetAllPropertyCultureValues( "excerpt", contentTypes[content.ContentTypeId], (c, ct, culture) => { // don't set it if it's already set var currentExcerpt = c.GetValue("excerpt", culture?.Culture)?.ToString(); if (!currentExcerpt.IsNullOrWhiteSpace()) { return(null); } if (content.HasProperty("richText")) { var richTextProperty = ct.CompositionPropertyTypes.First(x => x.Alias == "richText"); var val = c.GetValue <string>("richText", richTextProperty.VariesByCulture() ? culture?.Culture : null); return(_configs.Articulate().GenerateExcerpt(val)); } else { var markdownProperty = ct.CompositionPropertyTypes.First(x => x.Alias == "markdown"); var val = c.GetValue <string>("markdown", markdownProperty.VariesByCulture() ? culture?.Culture : null); var md = new Markdown(); var html = md.Transform(val); return(_configs.Articulate().GenerateExcerpt(html)); } }); //now fill in the social description if it is empty with the excerpt if (content.HasProperty("socialDescription")) { content.SetAllPropertyCultureValues( "socialDescription", contentTypes[content.ContentTypeId], (c, ct, culture) => { // don't set it if it's already set var currentSocialDescription = c.GetValue("socialDescription", culture?.Culture)?.ToString(); if (!currentSocialDescription.IsNullOrWhiteSpace()) { return(null); } var excerptProperty = ct.CompositionPropertyTypes.First(x => x.Alias == "excerpt"); return(content.GetValue <string>("excerpt", excerptProperty.VariesByCulture() ? culture?.Culture : null)); }); } } } } }
public async Task <IViewComponentResult> InvokeAsync() { var models = await _contentTypeService.GetAll().AsNoTracking().Where(c => c.IsActive).OrderBy(ct => ct.DisplaySort).ToListAsync(); return(View(models)); }
public async Task <IActionResult> ContentType() { var contentTypes = await _contentTypeService.GetAll().ToListAsync(); return(View(contentTypes)); }
public bool AllowsCultureVariation() { IEnumerable <IContentType> contentTypes = _contentTypeService.GetAll(); return(contentTypes.Any(contentType => contentType.VariesByCulture())); }
public async Task <IViewComponentResult> InvokeAsync() { var contentTypes = await _contentTypeService.GetAll().AsNoTracking().Where(c => c.IsActive).Include(c => c.Conetnts).OrderByDescending(c => c.Conetnts.Count).ToListAsync(); return(View(contentTypes)); }