umbraco/Umbraco.Forms.Issues

Magic strings won't work when using Custom Routes

Closed this issue · 3 comments

We've upgrade a site from CMS 10.6.1 to 13.3.2, and from Forms 10.4.0 to 13.1.2. We are using Custom routing with ForUmbracoPage (as described in https://docs.umbraco.com/umbraco-cms/v/13.latest-lts/reference/routing/custom-routes#custom-route-with-forumbracopage) and on the page being rendered via that custom controller we have a Form. Inside that form are default values with a magic string but after updating this doesn't work anymore and we see the literal magic string being displayed in the input (for example [@url]). When using magic strings on normale pages without custom routing it's working fine, so my guess is that something changed when using custom routing in combination with magic strings.


This item has been added to our backlog AB#41979

I've had a look into this one today, but haven't been able to replicate. I'll replay back my simple setup that I've used to try to see the issue, and maybe you can either try it in your installation or see what might differ in your presumably more complex setup.

I'm using content from the Umbraco starter kit.

Firstly my controller:

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Umbraco.Cms.Web.Common.Controllers;

namespace Umbraco.Forms.TestSite.Controllers;

public class PersonPageTestController : UmbracoPageController
{
    public PersonPageTestController(
        ILogger<UmbracoPageController> logger,
        ICompositeViewEngine compositeViewEngine)
        : base(logger, compositeViewEngine)
    { }

    [HttpGet]
    public IActionResult Index()
    {
        return View(CurrentPage);
    }
}

My composer:

using Microsoft.AspNetCore.Mvc.Filters;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Web.Common.ApplicationBuilder;
using Umbraco.Forms.TestSite.Controllers;

namespace Umbraco.Forms.Testsite.Business;

public class TestSiteComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.Services.Configure<UmbracoPipelineOptions>(options =>
        {
            options.AddFilter(new UmbracoPipelineFilter(nameof(PersonPageTestController))
            {
                Endpoints = app => app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllerRoute(
                        "Person Page Controller",
                        "/person-page/",
                        new { Controller = "PersonPageTest", Action = "Index" })
                        .ForUmbracoPage(FindContent);
                })
            });
        });
    }

    private IPublishedContent FindContent(ActionExecutingContext actionExecutingContext)
    {
        var umbracoContextAccessor = actionExecutingContext.HttpContext.RequestServices
            .GetRequiredService<IUmbracoContextAccessor>();
        var umbracoContext = umbracoContextAccessor.GetRequiredUmbracoContext();
        return umbracoContext!.Content!.GetById(1108)!;
    }
}

And my partial view:

@using Microsoft.Extensions.Options;
@using Umbraco.Cms.Web.Common.PublishedModels;
@using Umbraco.Forms.Core.Configuration;
@using Umbraco.Forms.Web;
@using Umbraco.Forms.Web.Extensions;
@using Umbraco.Cms.Core.Configuration.Models;

@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;

@addTagHelper *, Umbraco.Forms.Web

@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.Person>

@{
    Layout = null;

    var formId = Guid.Parse("3b40ecd3-ca17-4625-afd5-10a4ff02b68a");
}
<html>
<head>
    <title>Person Page</title>
</head>
<body>
    <h1>Person Page</h1>

    <div>Name: @Model.Name</div>

    <umb-forms-render form-id="@formId" theme="default" exclude-scripts="true" />

    @Html.RenderUmbracoFormDependencies(Url)

    <umb-forms-render-scripts theme="default" />
    
</body>
</html>

I've hard-coded reference to a form here that has two magic strings - a dictionary translation for a placeholder and the URL one that you have used to get the current page's URL. Both render as expected:

image

You're right. In our empty framework-site the code is working fine and as expected. When i copy over the exact same code in our full-blown solution it's not working anymore. For now i've added a workaround since it's a very specific scenario for us, but it seems something in our solution is interfering here.

OK, thanks for getting back. I'll close this then given you have worked around it and I assume won't need to investigate more deeply. But if you do surface something please feel free to add here and re-open the issue.