Creating a Custom Property Editor - Get current content page Id?
I've created custom sections, list-views, all pulling in data from custom database tables.
For my next trick, I'm looking to create a Property editor that pulls in/saves data to a custom table with the associated page Id.
I'm just not sure how to pass the current page id to my Angular functions in order to call the correct data. Forgive me for being such an Angular newb. I'm slowly getting there!
So, for example I'm envisioning having to specify an angular resource such as:
angular.module("umbraco.resources")
.factory("bookingResource", function ($http) {
return {
getItemsById: function (id) {
return $http.get("backoffice/BookingsAdmin/BookingsApi/GetItemsById?id=" + id);
}
};
});
So this will call the appropriate backoffice APIController. I just can't for the life of me think of how to pass the current page Id there?
EDIT: Since this is the accepted answer, I should note that Tim's answer below is probably better. That is, he says to use this instead:
editorState.current.id
I suspect that is better because it is more likely to work in something like the dialog that appears when you click "Edit" under a picked node in a multinode treepicker.
Interesting. I wonder if editorState.current.id is preferable to $routeParams.id. I think it might be, such as in the case that a page is opened for editing in a dialog (i.e., the URL wouldn't necessarily change, but the editor state for that dialog may). This is possible, for example, from the multinode treepicker when the experiment edit mode is enabled.
Creating a Custom Property Editor - Get current content page Id?
I've created custom sections, list-views, all pulling in data from custom database tables.
For my next trick, I'm looking to create a Property editor that pulls in/saves data to a custom table with the associated page Id.
I'm just not sure how to pass the current page id to my Angular functions in order to call the correct data. Forgive me for being such an Angular newb. I'm slowly getting there!
So, for example I'm envisioning having to specify an angular resource such as:
So this will call the appropriate backoffice APIController. I just can't for the life of me think of how to pass the current page Id there?
It seems like the Umbraco codebase does that by looking at $routeParams.id (and that comes from the URL, I believe): https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js#L129
EDIT: Since this is the accepted answer, I should note that Tim's answer below is probably better. That is, he says to use this instead:
I suspect that is better because it is more likely to work in something like the dialog that appears when you click "Edit" under a picked node in a multinode treepicker.
Of course!!! Fantastic!
Although I think the section you've referenced refers to the starting NodeId of a content picker. But still, there should be something here I can use.
Thanks!
See this thread: https://our.umbraco.org/forum/umbraco-7/developing-umbraco-7-packages/48154-How-to-get-current-ID-within-v7-Property-Editor
In short, this should probably do the trick for you though:
Don't forget to include editorState in your call.
Interesting. I wonder if editorState.current.id is preferable to $routeParams.id. I think it might be, such as in the case that a page is opened for editing in a dialog (i.e., the URL wouldn't necessarily change, but the editor state for that dialog may). This is possible, for example, from the multinode treepicker when the experiment edit mode is enabled.
Here is some documentation on editorState: http://umbraco.github.io/Belle/#/api/umbraco.services.editorState
Just to report back,
did the trick!
is working on a reply...