From 94b3b1f0fee1c4d0dcccd9637814dbc921ec4ed0 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Wed, 16 Jun 2021 15:23:28 +0100 Subject: [PATCH] Added extension method to get the icon from an PublishedContentType This is particularly helpful (to me) when using the RenderMacro editor. --- .../PublishedContentTypeExtensions.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/Umbraco.Community.Contentment/Web/Extensions/PublishedContentTypeExtensions.cs diff --git a/src/Umbraco.Community.Contentment/Web/Extensions/PublishedContentTypeExtensions.cs b/src/Umbraco.Community.Contentment/Web/Extensions/PublishedContentTypeExtensions.cs new file mode 100644 index 00000000..8ea74232 --- /dev/null +++ b/src/Umbraco.Community.Contentment/Web/Extensions/PublishedContentTypeExtensions.cs @@ -0,0 +1,25 @@ +/* Copyright © 2021 Lee Kelleher. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +using Umbraco.Community.Contentment.DataEditors; +using Umbraco.Core.Models.PublishedContent; +using Umbraco.Core.Services; +using UmbConstants = Umbraco.Core.Constants; + +namespace Umbraco.Web +{ + public static class PublishedContentTypeExtensions + { + public static string GetIcon(this IPublishedContentType contentType, IContentTypeService contentTypeService = null) + { + if (contentType != null && ContentTypeCacheHelper.TryGetIcon(contentType.Alias, out var icon, contentTypeService) == true) + { + return icon; + } + + return UmbConstants.Icons.DefaultIcon; + } + } +}