Property Editor breaking the doctype manager due to Umbraco executing it?
Hiya,
So I've built a rather complex property editor for Umbraco but once the property editor was completed, I noticed that I couldn't add it to any doctypes. Umbraco would post back an Automapper error, which is "technically" the correct error but very misleading as the issue was further up the call stack.
Confused, I downloaded the Umbraco source to track down the problem and noticed that the issue was in the class Umbraco.Web.Editors.ContentTypeController, specifically the PostSave(DocumentTypeSave contentTypeSave) function. This function was not able to convert the JSON sent to it correctly.
What I discovered was that my property editor was actually being executed by Umbraco in the doctype manager.
Is that supposed to happen?
Because it was being executed, one of my lines of code in the controller has something like this:
$scope.model.value = {};
(actually the {} represents a more complicated object but for the sake of brevity I've excluded it).
And it's that (I think) that seems to break the save function on the doctype manager. If I removed this code from my controller, Umbraco is able to save the property editor on the doctype.
So my question is two-fold. Firstly, is Umbraco supposed to execute the property editor in the doctype manager?
And second, if that's by design, how on earth can I prevent this being executed in the doctype manager as my calculation of $scope.model.value is breaking it. Am I potentially doing this wrong? I don't really want to have to comment out bits of the property editor every time I want to add it to a doctype :)
I think this is an unintended side effect of a relatively recent change to the visual design of the doctype editor. The change that was made was to show a preview of the property editor in the doctype editor. I'm not sure there is an official stance on how to handle property editors when rendered from the doctype editor, but I'd recommend failing gracefully.
There might be some way to detect if the property editor is in the doctype editor. Maybe others know more about that.
Does anybody know of a way to detect if a property editor is on a content node or if it's on the doctype editor?
One caveat I would mention is that a property editor may appear in other contexts. For example, it might appear in an Archetype, and it might appear in the Merchello section rather than in the content section. It might be worthwhile to ensure it works in a variety of contexts without necessarily knowing which particular context it is within.
Yes that matches what I'm seeing (and I'm rather glad it wasn't something I was doing wrong :) ). The property editor does indeed render a sort of preview in the doctype editor (the prop editor creates on the fly SVGs) so it's clearly running the controller of the property editor but it's then unable to save it.
Interestingly, if I add my property editor, attempt to save the doctype, clear the failure notice and replace the property editor with a textarea then the textarea shows a [Object object] within it which clearly shouldn't be there. So the property editor is definitely able to add something to the page and I think that's the point of failure. Ideally it should be sandboxed.
I'd be interesting to know if anyone has any suggestions on how to check the context or even turn off the preview as, currently, it's impossible to add complex property editors to doctypes.
It might be worthwhile looking into why the core property editors don't seem to have any issues. Maybe they are using some particular pattern that avoids the issue.
Otherwise, it might be worth reporting a bug. I have definitely seen this on a few property editors, so it's not just you experiencing issues (though, the issues I've seen have been fairly innocuous so far).
Property Editor breaking the doctype manager due to Umbraco executing it?
Hiya,
So I've built a rather complex property editor for Umbraco but once the property editor was completed, I noticed that I couldn't add it to any doctypes. Umbraco would post back an Automapper error, which is "technically" the correct error but very misleading as the issue was further up the call stack.
Confused, I downloaded the Umbraco source to track down the problem and noticed that the issue was in the class Umbraco.Web.Editors.ContentTypeController, specifically the PostSave(DocumentTypeSave contentTypeSave) function. This function was not able to convert the JSON sent to it correctly.
What I discovered was that my property editor was actually being executed by Umbraco in the doctype manager.
Is that supposed to happen?
Because it was being executed, one of my lines of code in the controller has something like this:
$scope.model.value = {};
(actually the {} represents a more complicated object but for the sake of brevity I've excluded it).
And it's that (I think) that seems to break the save function on the doctype manager. If I removed this code from my controller, Umbraco is able to save the property editor on the doctype.
So my question is two-fold. Firstly, is Umbraco supposed to execute the property editor in the doctype manager?
And second, if that's by design, how on earth can I prevent this being executed in the doctype manager as my calculation of $scope.model.value is breaking it. Am I potentially doing this wrong? I don't really want to have to comment out bits of the property editor every time I want to add it to a doctype :)
Any advice greatly received :)
I think this is an unintended side effect of a relatively recent change to the visual design of the doctype editor. The change that was made was to show a preview of the property editor in the doctype editor. I'm not sure there is an official stance on how to handle property editors when rendered from the doctype editor, but I'd recommend failing gracefully.
There might be some way to detect if the property editor is in the doctype editor. Maybe others know more about that.
Does anybody know of a way to detect if a property editor is on a content node or if it's on the doctype editor?
One caveat I would mention is that a property editor may appear in other contexts. For example, it might appear in an Archetype, and it might appear in the Merchello section rather than in the content section. It might be worthwhile to ensure it works in a variety of contexts without necessarily knowing which particular context it is within.
Thanks for the reply, much appreciated :)
Yes that matches what I'm seeing (and I'm rather glad it wasn't something I was doing wrong :) ). The property editor does indeed render a sort of preview in the doctype editor (the prop editor creates on the fly SVGs) so it's clearly running the controller of the property editor but it's then unable to save it.
Interestingly, if I add my property editor, attempt to save the doctype, clear the failure notice and replace the property editor with a textarea then the textarea shows a [Object object] within it which clearly shouldn't be there. So the property editor is definitely able to add something to the page and I think that's the point of failure. Ideally it should be sandboxed.
I'd be interesting to know if anyone has any suggestions on how to check the context or even turn off the preview as, currently, it's impossible to add complex property editors to doctypes.
Is this something I should report as a bug?
It might be worthwhile looking into why the core property editors don't seem to have any issues. Maybe they are using some particular pattern that avoids the issue.
Otherwise, it might be worth reporting a bug. I have definitely seen this on a few property editors, so it's not just you experiencing issues (though, the issues I've seen have been fairly innocuous so far).
is working on a reply...