Beispiel #1
0
        private void PackageDocumentTypes(PackageDefinition definition, XContainer root)
        {
            var contentTypes = new HashSet <IContentType>();
            var docTypesXml  = new XElement("DocumentTypes");

            foreach (var dtId in definition.DocumentTypes)
            {
                if (!int.TryParse(dtId, out var outInt))
                {
                    continue;
                }
                var contentType = _contentTypeService.Get(outInt);
                if (contentType == null)
                {
                    continue;
                }
                AddDocumentType(contentType, contentTypes);
            }
            foreach (var contentType in contentTypes)
            {
                docTypesXml.Add(_serializer.Serialize(contentType));
            }

            root.Add(docTypesXml);
        }
Beispiel #2
0
        public int CreateErrorNode(string documentTypeAlias, string nodeName, IDomainService domainService)
        {
            var docType   = contentTypeService.Get(documentTypeAlias);
            var languages = domainService.GetAll(false);

            try
            {
                IContent node = contentService.Create(nodeName, -1, documentTypeAlias);
                node.Name = nodeName;
                foreach (var language in languages)
                {
                    node.SetCultureName(nodeName, language.LanguageIsoCode);
                }

                contentService.Save(node);

                ConnectorContext.AuditService.Add(AuditType.New, -1, node.Id, "Error Content Node", $"Generic Error Node {nodeName} has been created");
                return(node.Id);
            }
            catch (Exception ex)
            {
                logger.Error(typeof(NodeHelper), ex.Message);
                logger.Error(typeof(NodeHelper), ex.StackTrace);
                throw;
            }
        }
Beispiel #3
0
        public override IContent FindItem(XElement node)
        {
            var key = node.GetKey();

            if (key != Guid.Empty)
            {
                var item = FindItem(key);
                if (item != null)
                {
                    return(item);
                }
            }

            var contentTypeAlias = node.Name.LocalName;

            if (this.IsEmpty(node))
            {
                contentTypeAlias = node.GetAlias();
            }

            var contentType = contentTypeService.Get(contentTypeAlias);

            if (contentType != null)
            {
                var blueprints = contentService.GetBlueprintsForContentTypes(contentType.Id);
                if (blueprints != null && blueprints.Any())
                {
                    return(blueprints.FirstOrDefault(x => x.Name == node.GetAlias()));
                }
            }

            return(null);
        }
        string IMetaWeblog.AddPost(string blogid, string username, string password, MetaWeblogPost post, bool publish)
        {
            var user = ValidateUser(username, password);

            var root = BlogRoot();

            var node = root.ChildrenOfType(ArticulateConstants.ArticulateArchiveContentTypeAlias).FirstOrDefault();

            if (node == null)
            {
                throw new XmlRpcFaultException(0, "No Articulate Archive node found");
            }

            var contentType = _contentTypeService.Get("ArticulateRichText");

            if (contentType == null)
            {
                throw new InvalidOperationException("No content type found with alias 'ArticulateRichText'");
            }

            var content = _contentService.CreateWithInvariantOrDefaultCultureName(
                post.Title, node.Id, contentType, _localizationService, user.Id);

            var extractFirstImageAsProperty = false;

            if (root.HasProperty("extractFirstImage"))
            {
                extractFirstImageAsProperty = root.Value <bool>("extractFirstImage");
            }

            AddOrUpdateContent(content, contentType, post, user, publish, extractFirstImageAsProperty);

            return(content.Id.ToString(CultureInfo.InvariantCulture));
        }
Beispiel #5
0
        public void Initialize()
        {
            try
            {
                var basePage = _contentTypeService.Get(DOCUMENT_PAGE_BASE);
                if (basePage != null)
                {
                    var pages = _contentTypeService.GetAll().Where(p => p.ParentId == basePage.Id);
                    if (pages != null && pages.Any())
                    {
                        foreach (var page in pages)
                        {
                            var contentType = _contentTypeService.Get(page.Id);
                            if (contentType != null)
                            {
                                var changed = false;

                                if (!contentType.PropertyTypeExists($"{propertyAlias}Description"))
                                {
                                    PropertyType metaDescriptionPropType = new PropertyType(_dataTypeService.GetDataType(-88), $"{propertyAlias}Description")
                                    {
                                        Name       = $"Description {propertyName}",
                                        Variations = ContentVariation.Culture
                                    };
                                    contentType.AddPropertyType(metaDescriptionPropType, META_TAB);
                                    changed = true;
                                }

                                if (changed)
                                {
                                    _contentTypeService.Save(contentType);
                                    ConnectorContext.AuditService.Add(AuditType.New, -1, page.Id, "Document Type", $"Document Type '{contentType.Alias}' has been updated");
                                }
                            }
                        }
                    }

                    foreach (var str in DOCUMENT_TYPE_WHITELIST.Split(','))
                    {
                        var page = _contentTypeService.Get(str);
                        if (!page.PropertyTypeExists($"{propertyAlias}Description"))
                        {
                            PropertyType metaDescriptionPropType = new PropertyType(_dataTypeService.GetDataType(-88), $"{propertyAlias}Description")
                            {
                                Name       = $"Description {propertyName}",
                                Variations = ContentVariation.Culture
                            };
                            page.AddPropertyType(metaDescriptionPropType, META_TAB);
                            _contentTypeService.Save(page);
                            ConnectorContext.AuditService.Add(AuditType.New, -1, page.Id, "Document Type", $"Document Type '{page.Alias}' has been updated");
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                _logger.Error(typeof(_44_MetaTagOnAllPagesMigration), ex.Message);
                _logger.Error(typeof(_44_MetaTagOnAllPagesMigration), ex.StackTrace);
            }
        }
        public override PipelineResult <InstallPipelineContext> Execute(PipelineArgs <InstallPipelineContext> args)
        {
            using (var scope = _scopeProvider.CreateScope())
            {
                var vendrCheckoutPageContenType     = _contentTypeService.Get(VendrCheckoutConstants.ContentTypes.Aliases.CheckoutPage);
                var vendrCheckoutStepPageContenType = _contentTypeService.Get(VendrCheckoutConstants.ContentTypes.Aliases.CheckoutStepPage);

                // Check to see if the checkout node already exists
                var filter     = scope.SqlContext.Query <IContent>().Where(x => x.ContentTypeId == vendrCheckoutPageContenType.Id);
                var childNodes = _contentService.GetPagedChildren(args.Model.SiteRootNodeId, 1, 1, out long totalRecords, filter);

                if (totalRecords == 0)
                {
                    // Create the checkout page
                    var checkoutNode = _contentService.CreateAndSave("Checkout", args.Model.SiteRootNodeId,
                                                                     VendrCheckoutConstants.ContentTypes.Aliases.CheckoutPage);

                    // Create the checkout steps pages
                    CreateCheckoutStepPage(checkoutNode, "Customer Information", "Information", "Information");
                    CreateCheckoutStepPage(checkoutNode, "Shipping Method", "Shipping Method", "ShippingMethod");
                    CreateCheckoutStepPage(checkoutNode, "Payment Method", "Payment Method", "PaymentMethod");
                    CreateCheckoutStepPage(checkoutNode, "Review Order", "Review", "Review");
                    CreateCheckoutStepPage(checkoutNode, "Process Payment", "Payment", "Payment");
                    CreateCheckoutStepPage(checkoutNode, "Order Confirmation", "Confirmation", "Confirmation");
                }

                scope.Complete();
            }

            // Continue the pipeline
            return(Ok());
        }
Beispiel #7
0
        private PublishedContentType CreatePublishedContentType(PublishedItemType itemType, string alias)
        {
            if (GetPublishedContentTypeByAlias != null)
            {
                return(GetPublishedContentTypeByAlias(alias));
            }

            IContentTypeComposition contentType;

            switch (itemType)
            {
            case PublishedItemType.Content:
                contentType = _contentTypeService.Get(alias);
                break;

            case PublishedItemType.Media:
                contentType = _mediaTypeService.Get(alias);
                break;

            case PublishedItemType.Member:
                contentType = _memberTypeService.Get(alias);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(itemType));
            }

            if (contentType == null)
            {
                throw new Exception($"ContentTypeService failed to find a {itemType.ToString().ToLower()} type with alias \"{alias}\".");
            }

            return(_publishedContentTypeFactory.CreateContentType(contentType));
        }
        protected override ActionResult <TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
        {
            var nodes = new TreeNodeCollection();

            //get all blueprints
            var entities = _entityService.GetChildren(Constants.System.Root, UmbracoObjectTypes.DocumentBlueprint).ToArray();

            //check if we're rendering the root in which case we'll render the content types that have blueprints
            if (id == Constants.System.RootString)
            {
                //get all blueprint content types
                var contentTypeAliases = entities.Select(x => ((IContentEntitySlim)x).ContentTypeAlias).Distinct();
                //get the ids
                var contentTypeIds = _contentTypeService.GetAllContentTypeIds(contentTypeAliases.ToArray()).ToArray();

                //now get the entities ... it's a bit round about but still smaller queries than getting all document types
                var docTypeEntities = contentTypeIds.Length == 0
                    ? new IEntitySlim[0]
                    : _entityService.GetAll(UmbracoObjectTypes.DocumentType, contentTypeIds).ToArray();

                nodes.AddRange(docTypeEntities
                               .Select(entity =>
                {
                    var treeNode      = CreateTreeNode(entity, Constants.ObjectTypes.DocumentBlueprint, id, queryStrings, Constants.Icons.ContentType, true);
                    treeNode.Path     = $"-1,{entity.Id}";
                    treeNode.NodeType = "document-type-blueprints";
                    // TODO: This isn't the best way to ensure a no operation process for clicking a node but it works for now.
                    treeNode.AdditionalData["jsClickCallback"] = "javascript:void(0);";
                    return(treeNode);
                }));

                return(nodes);
            }

            if (!int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId))
            {
                return(nodes);
            }

            //Get the content type
            var ct = _contentTypeService.Get(intId);

            if (ct == null)
            {
                return(nodes);
            }

            var blueprintsForDocType = entities.Where(x => ct.Alias == ((IContentEntitySlim)x).ContentTypeAlias);

            nodes.AddRange(blueprintsForDocType
                           .Select(entity =>
            {
                var treeNode  = CreateTreeNode(entity, Constants.ObjectTypes.DocumentBlueprint, id, queryStrings, Constants.Icons.Blueprint, false);
                treeNode.Path = $"-1,{ct.Id},{entity.Id}";
                return(treeNode);
            }));

            return(nodes);
        }
 public static void AddAllowedDocumentType(IContentTypeService service, string parentAlias, string childAlias, int order = -1)
 {
     var parent = service.Get(parentAlias);
     var child = service.Get(childAlias);
     var allowed = parent.AllowedContentTypes.ToList();
     allowed.Add(new Core.Models.ContentTypeSort(child.Id, order == -1 ? allowed.Count() : order));
     parent.AllowedContentTypes = allowed;
     service.Save(parent);
 }
        public ContentNodeBuilder CreateRoot()
        {
            var homeContentType = _contentTypeService.Get("home");

            _initialComponent = new Parent(_contentService, homeContentType, "Home");
            _components       = new List <Component>();

            _components.Add(_component);

            return(this);
        }
        private void CreateConfirmEmailDocumentType()
        {
            try
            {
                var container     = contentTypeService.GetContainers(CONTAINER, 1).FirstOrDefault();
                var containerId   = container.Id;
                var contentType   = contentTypeService.Get(DOCUMENT_TYPE_ALIAS);
                var parentDocType = contentTypeService.Get(PARENT_DOCUMENT_TYPE_ALIAS);
                if (contentType == null)
                {
                    ContentType docType = (ContentType)contentType ?? new ContentType(containerId)
                    {
                        Name          = DOCUMENT_TYPE_NAME,
                        Alias         = DOCUMENT_TYPE_ALIAS,
                        AllowedAsRoot = false,
                        Description   = DOCUMENT_TYPE_DESCRIPTION,
                        Icon          = ICON,
                        SortOrder     = 0,
                        Variations    = ContentVariation.Culture,
                        ParentId      = parentDocType.Id
                    };

                    // Create the Template if it doesn't exist
                    if (fileService.GetTemplate(TEMPLATE_ALIAS) == null)
                    {
                        //then create the template
                        Template newTemplate = new Template(TEMPLATE_NAME, TEMPLATE_ALIAS);
                        fileService.SaveTemplate(newTemplate);
                    }

                    // Set templates for document type
                    var template = fileService.GetTemplate(TEMPLATE_ALIAS);
                    docType.AllowedTemplates = new List <ITemplate> {
                        template
                    };
                    docType.SetDefaultTemplate(template);

                    contentTypeService.Save(docType);

                    // set as allowed content type in home
                    ContentHelper.AddAllowedDocumentType(contentTypeService, Phase2MergedHomeDocumentType.DOCUMENT_TYPE_ALIAS, DOCUMENT_TYPE_ALIAS);
                    ConfigureMasterTemplate();

                    ConnectorContext.AuditService.Add(AuditType.New, -1, docType.Id, "Document Type", $"Document Type '{DOCUMENT_TYPE_NAME}' has been created");

                    ContentHelper.CopyPhysicalAssets(new Milestone7EmbeddedResources());
                }
            }
            catch (System.Exception ex)
            {
                logger.Error(typeof(_07_ResetPasswordViaEmailDocumentType), ex.Message);
                logger.Error(typeof(_07_ResetPasswordViaEmailDocumentType), ex.StackTrace);
            }
        }
Beispiel #12
0
        /// <inheritdoc />
        public IEnumerable <string> GetBlockPlaceholderValues(Guid blockId, string propertyGroupAlias, CancellationToken cancellationToken)
        {
            var block           = _futureNhsContentService.GetPublishedContent(blockId, cancellationToken);
            var contentType     = _contentTypeService.Get(block.ContentType.Alias);
            var propertyGroup   = contentType.PropertyGroups.FirstOrDefault(x => x.Alias == propertyGroupAlias);
            var groupProperties = propertyGroup?.PropertyTypes.Select(x => x.Alias);

            return((from property in block.Properties.Where(x => groupProperties != null && groupProperties.Contains(x.Alias))
                    let converter = _converters.FirstOrDefault(x => x.EditorAlias.Equals(property.PropertyType.EditorAlias))
                                    where converter != null
                                    select property.GetValue().ToString()).ToList());
        }
        public ActionResult <DocumentTypeDisplay> GetById(int id)
        {
            var ct = _contentTypeService.Get(id);

            if (ct == null)
            {
                return(NotFound());
            }

            var dto = _umbracoMapper.Map <IContentType, DocumentTypeDisplay>(ct);

            return(dto);
        }
Beispiel #14
0
        // no MapAll - take care
        private void Map(DocumentTypeSave source, IContentType target, MapperContext context)
        {
            MapSaveToTypeBase <DocumentTypeSave, PropertyTypeBasic>(source, target, context);
            MapComposition(source, target, alias => _contentTypeService.Get(alias));

            target.AllowedTemplates = source.AllowedTemplates
                                      .Where(x => x != null)
                                      .Select(_fileService.GetTemplate)
                                      .Where(x => x != null)
                                      .ToArray();

            target.SetDefaultTemplate(source.DefaultTemplate == null ? null : _fileService.GetTemplate(source.DefaultTemplate));
        }
Beispiel #15
0
        /// <summary>
        /// When a new root Articulate node is created, then create the required 2 sub nodes
        /// </summary>
        private void ContentService_Saved(IContentService contentService, SaveEventArgs <IContent> e)
        {
            foreach (var c in e.SavedEntities)
            {
                if (!c.WasPropertyDirty("Id") || !c.ContentType.Alias.InvariantEquals(ArticulateContentTypeAlias))
                {
                    continue;
                }

                //it's a root blog node, set up the required sub nodes (archive , authors) if they don't exist

                var defaultLang = _languageService.GetDefaultLanguageIsoCode();

                var children = contentService.GetPagedChildren(c.Id, 0, 10, out var total).ToList();
                if (total == 0 || children.All(x => x.ContentType.Alias != ArticulateConstants.ArticulateArchiveContentTypeAlias))
                {
                    var archiveContentType = _contentTypeService.Get(ArticulateConstants.ArticulateArchiveContentTypeAlias);
                    if (archiveContentType != null)
                    {
                        if (archiveContentType.VariesByCulture())
                        {
                            var articles = contentService.Create("", c, ArticulateConstants.ArticulateArchiveContentTypeAlias);
                            articles.SetCultureName(ArticulateConstants.ArticlesDefaultName, defaultLang);
                            contentService.Save(articles);
                        }
                        else
                        {
                            var articles = contentService.CreateAndSave(ArticulateConstants.ArticlesDefaultName, c, ArticulateConstants.ArticulateArchiveContentTypeAlias);
                        }
                    }
                }

                if (total == 0 || children.All(x => x.ContentType.Alias != ArticulateConstants.ArticulateAuthorsContentTypeAlias))
                {
                    var authorContentType = _contentTypeService.Get(ArticulateConstants.ArticulateAuthorsContentTypeAlias);
                    if (authorContentType != null)
                    {
                        if (authorContentType.VariesByCulture())
                        {
                            var authors = contentService.Create("", c, ArticulateConstants.ArticulateAuthorsContentTypeAlias);
                            authors.SetCultureName(ArticulateConstants.AuthorsDefaultName, defaultLang);
                            contentService.Save(authors);
                        }
                        else
                        {
                            var authors = contentService.CreateAndSave(ArticulateConstants.AuthorsDefaultName, c, ArticulateConstants.ArticulateAuthorsContentTypeAlias);
                        }
                    }
                }
            }
        }
        public ClearCacheComponent(IContentTypeService contentTypeService, AppCaches appCaches)
        {
            appCaches.RuntimeCache.Clear();

            //Found an issue with cache not invalided due to Umbraco not being able to find Content Types
            //So to be on the safe side, I'm Saving the Content Types again, this may not be required but added just in case
            var seoContentType  = contentTypeService.Get("seo");
            var homeContentType = contentTypeService.Get("home");
            var pageContentType = contentTypeService.Get("contentPage");

            contentTypeService.Save(seoContentType);
            contentTypeService.Save(homeContentType);
            contentTypeService.Save(pageContentType);
        }
        /// <summary>
        /// Used to set a content item property values while taking into account if it's variant or invariant
        /// </summary>
        /// <param name="content"></param>
        /// <param name="propertyAlias"></param>
        /// <param name="propertyValue"></param>
        /// <param name="onlyIfNotSet"></param>
        private void SetPropertyValue <T>(IContent content, string propertyAlias, Func <IContentType, ContentCultureInfos, T> propertyValueGetter, bool onlyIfNotSet = false)
        {
            var contentType = _contentTypeService.Get(content.ContentType.Id);

            if (contentType == null)
            {
                throw new InvalidOperationException($"No content type found by id {content.ContentType.Id}");
            }

            if (content.ContentType.VariesByCulture())
            {
                foreach (var c in content.CultureInfos)
                {
                    var propertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == propertyAlias);
                    if (propertyType == null)
                    {
                        throw new InvalidOperationException($"No property type found by alias {propertyAlias}");
                    }

                    var propertyValue = propertyValueGetter(contentType, c);
                    if (propertyValue == null || (propertyValue is string propValAsString && string.IsNullOrWhiteSpace(propValAsString)))
                    {
                        continue;
                    }

                    if (onlyIfNotSet && (!content.GetValue <T>(propertyAlias, propertyType.VariesByCulture() ? c.Culture : null)?.Equals(default(T)) ?? false))
                    {
                        continue;
                    }

                    content.SetValue(propertyAlias, propertyValue, propertyType.VariesByCulture() ? c.Culture : null);
                }
            }
            else
            {
                var propertyValue = propertyValueGetter(contentType, null);
                if (propertyValue == null || (propertyValue is string propValAsString && string.IsNullOrWhiteSpace(propValAsString)))
                {
                    return;
                }

                if (onlyIfNotSet && (!content.GetValue <T>(propertyAlias)?.Equals(default(T)) ?? false))
                {
                    return;
                }

                content.SetValue(propertyAlias, propertyValue);
            }
        }
Beispiel #18
0
        private ContentTypeContainer GetContentTypesByAlias(string contentTypeAlias)
        {
            if (Guid.TryParse(contentTypeAlias, out Guid contentTypeGuid))
            {
                contentTypeAlias = GetContentTypeAliasByGuid(contentTypeGuid);
            }

            return((ContentTypeContainer)_appCaches.RuntimeCache.GetCacheItem(
                       string.Concat("Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypesByAlias_", contentTypeAlias),
                       () => new ContentTypeContainer
            {
                PublishedContentType = new PublishedContentType(_contentTypeService.Get(contentTypeAlias), _publishedContentTypeFactory),
                ContentType = _contentTypeService.Get(contentTypeAlias)
            }));
        }
        private void UpdateDocumentType()
        {
            try
            {
                // generic page
                var genericType = contentTypeService.Get(DOCUMENT_TYPE_ALIAS);
                if (genericType != null)
                {
                    var    richTextEditor      = dataTypeService.GetDataType("Full Rich Text Editor");
                    string propertyName        = "Page Content",
                           propertyDescription = "Text to be displayed on the Page";

                    PropertyType richTextPropType = new PropertyType(dataTypeService.GetDataType(richTextEditor.Id), "pageContent")
                    {
                        Name        = propertyName,
                        Description = propertyDescription,
                        Variations  = ContentVariation.Culture
                    };

                    genericType.AddPropertyType(richTextPropType, TAB);
                    contentTypeService.Save(genericType);
                    ConnectorContext.AuditService.Add(AuditType.Save, -1, genericType.Id, "Document Type", $"Document Type '{DOCUMENT_TYPE_ALIAS}' has been updated");
                }
            }
            catch (Exception ex)
            {
                logger.Error(typeof(_22_GamePageBodyText), ex.Message);
                logger.Error(typeof(_22_GamePageBodyText), ex.StackTrace);
            }
        }
        private ContentTypeContainer GetContentTypesByAlias(string contentTypeAlias)
        {
            if (Guid.TryParse(contentTypeAlias, out Guid contentTypeGuid))
            {
                contentTypeAlias = GetContentTypeAliasByGuid(contentTypeGuid);
            }

            return(_runtimeCache.GetCacheItem(
                       string.Concat("Bento.Core.Services.EmbeddedContentService.GetContentTypesByAlias_",
                                     contentTypeAlias),
                       () => new ContentTypeContainer
            {
                PublishedContentType = new PublishedContentType(_contentTypeService.Get(contentTypeAlias), Current.PublishedContentTypeFactory),
                ContentType = _contentTypeService.Get(contentTypeAlias)
            }));
        }
        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));
        }
        public static void AfterMapContentTypeSaveToEntity <TSource, TDestination>(TSource source, TDestination dest, IContentTypeService contentTypeService)
            where TSource : ContentTypeSave
            where TDestination : IContentTypeComposition
        {
            //sync compositions
            var current  = dest.CompositionAliases().ToArray();
            var proposed = source.CompositeContentTypes;

            var remove = current.Where(x => proposed.Contains(x) == false);
            var add    = proposed.Where(x => current.Contains(x) == false);

            foreach (var rem in remove)
            {
                dest.RemoveContentType(rem);
            }

            foreach (var a in add)
            {
                // TODO: Remove N+1 lookup
                var addCt = contentTypeService.Get(a);
                if (addCt != null)
                {
                    dest.AddContentType(addCt);
                }
            }
        }
        public IEnumerable <DataListItem> GetItems(Dictionary <string, object> config)
        {
            if (config.TryGetValueAs("contentType", out JArray array) == true &&
                array.Count > 0 &&
                array[0].Value <string>() is string str &&
                string.IsNullOrWhiteSpace(str) == false &&
                GuidUdi.TryParse(str, out var udi) == true)
            {
                var contentType = _contentTypeService.Get(udi.Guid);
                if (contentType != null)
                {
                    if (_icons == null)
                    {
                        _icons = _dataEditors.Value.ToDictionary(x => x.Alias, x => x.Icon);
                    }

                    return(contentType
                           .CompositionPropertyTypes
                           .Select(x => new DataListItem
                    {
                        Name = x.Name,
                        Value = x.Alias,
                        Description = x.PropertyEditorAlias,
                        Icon = _icons.ContainsKey(x.PropertyEditorAlias) == true
                                ? _icons[x.PropertyEditorAlias]
                                : UmbConstants.Icons.PropertyEditor,
                    }));
                }
            }

            return(Enumerable.Empty <DataListItem>());
        }
Beispiel #24
0
        private string GetIcon(LogDto logItem)
        {
            switch (logItem.EntityType.ToLower())
            {
            case "document":
                return(_contentService.GetById(logItem.NodeId).ContentType.Icon);

            case "media":
                return(_mediaService.GetById(logItem.NodeId).ContentType.Icon);

            case "member":
                return(_memberTypeService.Get(_memberService.GetById(logItem.NodeId).ContentTypeAlias).Icon);

            case "documenttype":
                return(_contentTypeService.Get(logItem.NodeId).Icon);

            case "mediatype":
                return(_mediaTypeService.Get(logItem.NodeId).Icon);

            case "membertype":
                return(_memberTypeService.Get(logItem.NodeId).Icon);

            case "datatype":
                return(_dataTypeService.GetAll(new[] { logItem.NodeId }).FirstOrDefault().Editor.Icon);

            case "dictionaryitem":
                return("icon-book-alt");

            default:
                return("icon-newspaper");
            }
        }
        private void UpdateHomeDocumentType()
        {
            try
            {
                var contentType = contentTypeService.Get(DOCUMENT_TYPE_ALIAS);
                if (contentType != null)
                {
                    if (!contentType.PropertyTypeExists("alternateDomains"))
                    {
                        PropertyType tenantAltDomainsPropType = new PropertyType(dataTypeService.GetDataType(-92), "alternateDomains")
                        {
                            Name        = "Alternate Domains",
                            Description = "Tenant Alternate Domains",
                            Variations  = ContentVariation.Nothing,
                            SortOrder   = 3
                        };
                        contentType.AddPropertyType(tenantAltDomainsPropType, TENANT_TAB);

                        contentTypeService.Save(contentType);
                        ConnectorContext.AuditService.Add(AuditType.Save, -1, contentType.Id, "Document Type", $"Document Type '{DOCUMENT_TYPE_ALIAS}' has been updated");
                    }
                }
            }
            catch (System.Exception ex)
            {
                logger.Error(typeof(_18_HomeAddAlternateDomains), ex.Message);
                logger.Error(typeof(_18_HomeAddAlternateDomains), ex.StackTrace);
            }
        }
Beispiel #26
0
        private void UpdateHomeDocumentType()
        {
            const string currenciesName        = "Tenant Currencies";
            const string currenciesDescription = "Total Code Tenant Used Currencies";
            const string currenciesAlias       = "tenantCurrencies";

            try
            {
                var contentType = contentTypeService.Get(DOCUMENT_TYPE_ALIAS);
                if (contentType != null)
                {
                    #region Tenant Currencies
                    var tenantCurrencies = contentType.PropertyTypes.SingleOrDefault(x => x.Alias == currenciesAlias);
                    if (tenantCurrencies == null)
                    {
                        PropertyType tenantCurrenciesPropType = new PropertyType(dataTypeService.GetDataType(-92), currenciesAlias)
                        {
                            Name        = currenciesName,
                            Description = currenciesDescription,
                            Variations  = ContentVariation.Nothing
                        };
                        contentType.AddPropertyType(tenantCurrenciesPropType, TENANT_TAB);
                        contentTypeService.Save(contentType);
                    }
                    #endregion
                }
            }
            catch (System.Exception ex)
            {
                logger.Error(typeof(_14_HomeDocumentTypeTenantCurrencies), ex.Message);
                logger.Error(typeof(_14_HomeDocumentTypeTenantCurrencies), ex.StackTrace);
            }
        }
Beispiel #27
0
        /// <summary>
        /// Gets a tours for a specific doctype
        /// </summary>
        /// <param name="doctypeAlias">The documenttype alias</param>
        /// <returns>A <see cref="BackOfficeTour"/></returns>
        public async Task <IEnumerable <BackOfficeTour> > GetToursForDoctype(string doctypeAlias)
        {
            var tourFiles = await this.GetTours();

            var doctypeAliasWithCompositions = new List <string>
            {
                doctypeAlias
            };

            var contentType = _contentTypeService.Get(doctypeAlias);

            if (contentType != null)
            {
                doctypeAliasWithCompositions.AddRange(contentType.CompositionAliases());
            }

            return(tourFiles.SelectMany(x => x.Tours)
                   .Where(x =>
            {
                if (string.IsNullOrEmpty(x.ContentType))
                {
                    return false;
                }
                var contentTypes = x.ContentType.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).Select(ct => ct.Trim());
                return contentTypes.Intersect(doctypeAliasWithCompositions).Any();
            }));
        }
Beispiel #28
0
        public InitialiseContentCreationBuilder UpdateContentTypes()
        {
            //Usually I wouldnt explcitly instantiate a class here, I would use DI with an IOC container but due to time, I stuck with this
            IContentTypeUpdateService contentTypeUpdateService = new ContentTypeUpdateService(_contentTypeService, _fileService, _dataTypeService);

            var seoContentType  = _contentTypeService.Get("seo");
            var homeContentType = _contentTypeService.Get("home");
            var pageContentType = _contentTypeService.Get("contentPage");

            if (seoContentType != null)
            {
                var contentTypeData = new ContentTypeData()
                {
                    Properties = new PropertyTypeData[] { new PropertyTypeData("Page Title", "pageTitle", "Textstring", "SEO") }
                };

                contentTypeUpdateService.Update(seoContentType, contentTypeData);
            }

            if (homeContentType != null)
            {
                var contentTypeData = new ContentTypeData()
                {
                    Template   = "Home",
                    Composites = new string[] { "seo" },
                    Properties = new PropertyTypeData[] { new PropertyTypeData("Body", "body", "Richtext editor", "Details") }
                };

                contentTypeUpdateService.Update(homeContentType, contentTypeData);
            }

            if (pageContentType != null)
            {
                var contentTypeData = new ContentTypeData()
                {
                    Template   = "Content Page",
                    Composites = new string[] { "seo" },
                    Properties = new PropertyTypeData[] { new PropertyTypeData("Body", "body", "Richtext editor", "Details") }
                };

                contentTypeUpdateService.Update(pageContentType, contentTypeData);
            }

            contentTypeUpdateService.SetAllowedContentTypes(homeContentType, new IContentType[] { pageContentType });

            return(this);
        }
Beispiel #29
0
        private IDictionary <string, string> GetAllowedTemplates(IContent source)
        {
            var contentType = _contentTypeService.Get(source.ContentTypeId);

            return(contentType.AllowedTemplates
                   .Where(t => t.Alias.IsNullOrWhiteSpace() == false && t.Name.IsNullOrWhiteSpace() == false)
                   .ToDictionary(t => t.Alias, t => _localizedTextService.UmbracoDictionaryTranslate(t.Name)));
        }
Beispiel #30
0
        private IPublishedContentType CreatePublishedContentType(PublishedItemType itemType, Guid key)
        {
            IContentTypeComposition contentType = itemType switch
            {
                PublishedItemType.Content => _contentTypeService.Get(key),
                PublishedItemType.Media => _mediaTypeService.Get(key),
                PublishedItemType.Member => _memberTypeService.Get(key),
                _ => throw new ArgumentOutOfRangeException(nameof(itemType)),
            };

            if (contentType == null)
            {
                throw new Exception($"ContentTypeService failed to find a {itemType.ToString().ToLower()} type with key \"{key}\".");
            }

            return(_publishedContentTypeFactory.CreateContentType(contentType));
        }