umbraco/Umbraco.Forms.Issues

Magic string to picker resolved as `Umbraco.Cms.Web.Common.PublishedModels`

Closed this issue · 6 comments

In a custom workflow I have a magic string reference to a page field like this [#employee] in Email field (inherited from SendRazorEmail workflow).

However when debugging it returns this string value Umbraco.Cms.Web.Common.PublishedModels.Employee and using _placeholderParsingService.ParsePlaceHolders(Email, false); didn't seem to make a difference.

I guess Umbraco Forms doesn't automatically resolve this picker, but only handle it as string value.

I tried if is could use a custom format function: https://docs.umbraco.com/umbraco-forms/developer/extending/adding-a-magic-string-format-function#creating-a-custom-format-function

[#employee | page]

but value just contain Umbraco.Cms.Web.Common.PublishedModels.Employee.

image

@AndyButland any way magic string can resolve value from a Content/MNTP picker on content page?

For now I can access page model directly though:
#578 (comment)

Just looking to see what's going on here, and can see we are getting the values for each property on the page like this:

foreach (IPublishedProperty property in content.Properties
    .Where(IncludePropertyForPageElements))
{
    if (!pageElements.ContainsKey(property.Alias))
    {
        var value = property.PropertyType.EditorAlias;
        pageElements.Add(property.Alias, property.Value(_publishedValueFallback));
    }
}

As we are using .Value, we'll get an instance of your published model object here.

And then when replacing the value, we call .ToString() which gives the result you've found.

Perhaps we could use .GetSourceValue() rather than Value(), so you'd have a GUID. But I don't see how that would help, as it's still not a value that's useful for replacing.

What you really want I assume is the node name here.

Would it be possible for you to override .ToString() on your Umbraco.Cms.Web.Common.PublishedModels.Employee object? That might do it. I know these are generated, but they are partial classes I believe, so perhaps that would work.

Actually in this specific usecase we want a custom property on Employee (an email property) in the workflow. The guid may help as we can lookup the employee from cache in the workflow. At the moment we just access it from page model.

However with the guid revolved, we could use a custom format fuction to revolve a specific property, e.g. similae to AngularJS filter ncNodeName. We could e.g. call it employeeEmail. Or maybe a build in custom format function to resolve a specific property from content node?

Closing as request has already been raised in #1205.

See further comment on #1205 (comment).