Skip to content

Commit

Permalink
Added extension method to get the icon from an PublishedContentType
Browse files Browse the repository at this point in the history
This is particularly helpful (to me) when using the RenderMacro editor.
  • Loading branch information
leekelleher committed Jun 16, 2021
1 parent 1421e3e commit 94b3b1f
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit 94b3b1f

Please sign in to comment.