Пример #1
0
        internal static PublishedContentType GetPublishedContentTypeFromItem(JObject item)
        {
            var contentTypeAlias = string.Empty;

            // First we check if the item has a content-type GUID...
            var contentTypeGuid = GetContentTypeGuidFromItem(item);

            if (contentTypeGuid.HasValue)
            {
                // HACK: If Umbraco's `PublishedContentType.Get` method supported a GUID parameter,
                // we could use that method directly, however it only supports the content-type alias (as of v7.4.0)
                // See: https://github.com/umbraco/Umbraco-CMS/blob/release-7.4.0/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs#L133
                // Our workaround is to cache a content-type GUID => alias lookup.

                ContentTypeCacheHelper.TryGetAlias(contentTypeGuid.Value, out contentTypeAlias, ApplicationContext.Current.Services.ContentTypeService);
            }

            // If we don't have the content-type alias at this point, check if we can get it from the item
            if (string.IsNullOrEmpty(contentTypeAlias))
            {
                contentTypeAlias = GetContentTypeAliasFromItem(item);
            }

            if (string.IsNullOrEmpty(contentTypeAlias))
            {
                return(null);
            }

            return(PublishedContentType.Get(PublishedItemType.Content, contentTypeAlias));
        }
Пример #2
0
 internal static void SetContentTypeGuid(JObject item, string contentTypeAlias, IContentTypeService contentTypeService)
 {
     if (ContentTypeCacheHelper.TryGetGuid(contentTypeAlias, out Guid key, contentTypeService))
     {
         item[InnerContentConstants.ContentTypeGuidPropertyKey] = key.ToString();
     }
 }