Custom FieldProvider for Umbraco.MultiNodeTreePicker is not setting the value in the CMS
I'm trying my hand at writing a custom FieldProvider; in this case for the Umbraco.MultiNodeTreePicker property editor. If I set a breakpoint I can see that my code is being executed (I have pasted it into this post below).
My code has a debug logging statement and I can see the results in the Umbraco CMS log. And it shows that my input value is being converted properly into the output value that I expect.
More information: When I run the import with the "auto publish" checkbox checked I get the following error in the UI:
Could not publish the document, property alias:'categories' has no value or is invalid
The property with alias 'categories' is the property using the MNTP in the new CMS.
In the Umbraco Log I find this:
System.ArgumentException: Could not publish the document, property alias:'categories' has no value or is invalid
at CMSImport.Providers.ImportProviders.ContentImport.ContentImportProvider.(IContent , Int32 )
at CMSImport.Providers.ImportProviders.ContentImport.ContentImportProvider.Import(ImportState state)
As you can see the method and parameter names are not coming through. In the string they're expressed as unicode u+0002, which means "Start of Text" and unicode u+0003, "end of text". Though I don't know the method name it appears to be expecting an IContent object and an int as parameters. If my custom FieldProvider value is being passed in to the int parameter I can see why it would throw an error.
So the question is ... why is the import of a string being handed off to a method that requires an int parameter?
More Info: Just to make absolutely sure that nothing in my custom FieldProvider was erroring out silently I commented everything out and hard coded the return string value.
Even with that I still get the same errors during the import.
Sorry for the delay in response. The reason you got this error was because after fieldprovider parsing it went through the advanced field provider. I've just released version 4.1.1. of CMSImport that respects the Break property in the Fieldprovider. If you set it to true in your code after parsing the values it will never go through the advanced field provider.
This is my test code
[FieldProvider(PropertyEditorAlias = "Umbraco.MultiNodeTreePicker")]
public class MntpCustomProvider : IFieldProvider
{
public object Parse(object value, ImportPropertyInfo property, FieldProviderOptions fieldProviderOptions)
{
fieldProviderOptions.Break = true;
return "umb://document/ce625e805b7a450d8240f688417ed6e6,umb://document/79a07efddb9e4097941fa3bbfedd0b3d";
}
}
I have a couple of questions. I am also going to be building a custom FieldProvider for my Nested Content properties in the new CMS. Will I need to set the fieldProviderOptions.Break property there as well?
And can you explain what role the FieldProviderAttribute.Priority setting plays? Do I ever need to use it? And do I set my priority to a higher number or a lower number?
Custom FieldProvider for Umbraco.MultiNodeTreePicker is not setting the value in the CMS
I'm trying my hand at writing a custom FieldProvider; in this case for the Umbraco.MultiNodeTreePicker property editor. If I set a breakpoint I can see that my code is being executed (I have pasted it into this post below).
My code has a debug logging statement and I can see the results in the Umbraco CMS log. And it shows that my input value is being converted properly into the output value that I expect.
BTW, I'm basing my work on what I read here: https://our.umbraco.com/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Multinode-Treepicker/
Also, during my import the "Auto publish" option is un-checked and the "Enable content updates" option is un-checked.
I'm running Umbraco CMS 8.11.1 and CMSImport 4.1.0.
There are no errors or warnings in the Umbraco Log. The content being imported does get created, however the MNTP properties have no values.
Hopefully, I'm missing something obvious. Can you tell me what it is? What am I doing wrong?
Thanks!
Here's my code:
I have confirmed, by looking in the database, that MNTP data is indeed saved as a comma-delimited list of UDIs. Like this:
And that's definitely what my FieldProvider is outputting.
More information: When I run the import with the "auto publish" checkbox checked I get the following error in the UI:
The property with alias 'categories' is the property using the MNTP in the new CMS.
In the Umbraco Log I find this:
As you can see the method and parameter names are not coming through. In the string they're expressed as unicode u+0002, which means "Start of Text" and unicode u+0003, "end of text". Though I don't know the method name it appears to be expecting an IContent object and an int as parameters. If my custom FieldProvider value is being passed in to the int parameter I can see why it would throw an error.
So the question is ... why is the import of a string being handed off to a method that requires an int parameter?
More Info: Just to make absolutely sure that nothing in my custom FieldProvider was erroring out silently I commented everything out and hard coded the return string value.
Even with that I still get the same errors during the import.
Hi Chester,
Sorry for the delay in response. The reason you got this error was because after fieldprovider parsing it went through the advanced field provider. I've just released version 4.1.1. of CMSImport that respects the Break property in the Fieldprovider. If you set it to true in your code after parsing the values it will never go through the advanced field provider.
This is my test code
Hope this helps,
Richard
Hi Richard,
This solution worked perfectly! Thank you.
I have a couple of questions. I am also going to be building a custom FieldProvider for my Nested Content properties in the new CMS. Will I need to set the fieldProviderOptions.Break property there as well?
And can you explain what role the FieldProviderAttribute.Priority setting plays? Do I ever need to use it? And do I set my priority to a higher number or a lower number?
Thanks! chester
Sigh ... I marked the wrong post as the solution. The post by Richard, above, is actually the solution!
Hi Chester,
Great it works. Nested Content is not yet supported (yet) so you don't need to set the Break property.
The priority can be set to make sure your provider is called before or after the default ones. My providers are always set to medium.
Hope this helps,
Richard
Thanks!!
is working on a reply...