Skip to content

Fallback ToLanguage with BlockList Regression #20350

@warrenbuckley

Description

@warrenbuckley

Which Umbraco version are you using?

16.2.0

Bug summary

When rendering content in a view, the contents of a BlockList are unable to fallback to a Default Language

Specifics

We have checked away from our implementation and compared against latest 16 (16.2.0) and latest 13 (13.10.1) to ensure it was nothing specific with our content or code.

Steps to reproduce

Video

This is a video explaining the content/datatype structure setup along with it working in V13 but not in V16 with the same code.

Blocklist-Language-Fallback-Bug_ENCODED_720.mp4

Code to override Fallback Value used with ModelsBuilder

using Umbraco.Cms.Core.Models.PublishedContent;

namespace Umbraco.Cms.Web.Common.PublishedModels;

public static class PublishedContentExtensions
{
    private static IPublishedValueFallback PublishedValueFallback { get; } =
        StaticServiceProvider.Instance.GetRequiredService<IPublishedValueFallback>();

    public static T? Value<T>(
        this IPublishedElement content,
        IPublishedValueFallback publishedValueFallback,
        string alias,
        string? culture = null,
        string? segment = null,
        Fallback fallback = default)
    {
        return content.Value<T>(publishedValueFallback, alias, culture, segment, Fallback.ToLanguage, default);
    }

    public static T? Value<T>(
        this IPublishedContent content,
        string alias,
        string? culture = null,
        string? segment = null,
        Fallback fallback = default)
    {
        return content.Value<T>(PublishedValueFallback, alias, culture, segment, Fallback.ToLanguage, default);
    }

    public static T? Value<T>(
        this IPublishedContent content,
        string alias)
    {
        return content.Value<T>(PublishedValueFallback, alias, null, null, Fallback.ToLanguage, default);
    }
}

testpage.cshtml - Template

@using Umbraco.Cms.Web.Common.PublishedModels;
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<TestPage>
@{
	Layout = null;
}

<h1>Static Content</h1>

<h2>Title .Value("alias") = @Model.Value("title", fallback: Fallback.ToLanguage)</h2>
<h2>Title Models Builder = @Model.Title</h2>
<h2>Title .ValueFor() = @Model.ValueFor(x => x.Title, fallback: Fallback.ToDefaultLanguage)</h2>

<hr/>

<h2>Block Grid</h2>
@Html.GetBlockListHtml(Model.BlockList)

Blocklist/Components/HeaderBlock - Block View Partial

@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockListItem>;
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
@{
    var content = (ContentModels.HeaderBlock)Model.Content;
}

<div style="border: solid red;margin-bottom: 10px;">

    <h2>I AM HeaderBlock Static</h2>

    <h3>Models = @content.HeaderTitle</h3>
    <h3>Value() @content.Value("headerTitle", fallback: Fallback.ToDefaultLanguage)</h3>
    <h3>ValueFor() @content.ValueFor(x=> x.HeaderTitle, fallback: Fallback.ToDefaultLanguage)</h3>

</div>

Expected result / actual result

That the BlockList and/or BlockGrid will fallback to the default language as before.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions