Skip to content

Commit

Permalink
Fixes BlogBanner is always empty #346
Browse files Browse the repository at this point in the history
  • Loading branch information
Shazwazza committed Jan 4, 2021
1 parent 94dd5fc commit ea338b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Articulate/Models/MasterModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors.ValueConverters;
using Umbraco.Web;
using Umbraco.Web.Models;

Expand Down Expand Up @@ -98,13 +100,13 @@ public string CustomRssFeed

public string BlogLogo
{
get => _blogLogo ?? (_blogLogo = RootBlogNode.GetCropUrl(propertyAlias: "blogLogo", imageCropMode: ImageCropMode.Max));
get => _blogLogo ?? (_blogLogo = RootBlogNode.GetArticulateCropUrl("blogLogo", Current.VariationContextAccessor?.VariationContext));
protected set => _blogLogo = value;
}

public string BlogBanner
{
get => _blogBanner ?? (_blogBanner = RootBlogNode.GetCropUrl(propertyAlias: "blogBanner", imageCropMode: ImageCropMode.Max));
get => _blogBanner ?? (_blogBanner = RootBlogNode.GetArticulateCropUrl("blogBanner", Current.VariationContextAccessor?.VariationContext));
protected set => _blogBanner = value;
}

Expand Down
28 changes: 27 additions & 1 deletion src/Articulate/Models/PublishedContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,37 @@
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors.ValueConverters;
using Umbraco.Web;
using Umbraco.Web.Models;

namespace Articulate.Models
{
public static class PublishedContentExtensions
{
public static string GetArticulateCropUrl(this IPublishedContent content, string propertyAlias, VariationContext variationContext)
{
if (!content.ContentType.VariesByCulture())
return content.GetCropUrl(propertyAlias: propertyAlias, imageCropMode: ImageCropMode.Max);

var property = content.GetProperty(propertyAlias);
if (property == null)
return string.Empty;

var culture = property.PropertyType.VariesByCulture()
? variationContext?.Culture
: string.Empty; // must be string empty, not null since that won't work :/

var url = content.MediaUrl(culture, UrlMode.Default, "blogBanner");
var cropUrl = content.Value<ImageCropperValue>("blogBanner", culture);
if (cropUrl != null)
{
return url.GetCropUrl(cropUrl, imageCropMode: ImageCropMode.Max);
}

return string.Empty;
}

public static IPublishedContent Next(this IPublishedContent content)
{
var found = false;
Expand Down Expand Up @@ -92,4 +118,4 @@ public static bool HasMoreThan<TSource>(this IEnumerable<TSource> source, int co
}

}
}
}

0 comments on commit ea338b3

Please sign in to comment.