Capture the Umbraco CMS Publish Button Click Event on Client Side Code
I Have Created a Website in that i am having a Section in that i render a blog , but now i want to capture the umbraco publish button event on client side so using that i can post that blog to other sites as well , please help me for this .
Capturing the Publish button click event form umbraco cms side to my client side.
Possibly a few different ways to do this, but I'd try using an AngularJs HTTP interceptor, to capture requests to the /postsave endpoint where the action is publish.
Pretty sure the request includes the complete content item, so you'd be able to check the content type, extract any property values, and do with them whatever you need.
The interceptor is simply a service factory with request and response methods (only interested in request in this example):
(() => {
function interceptor($q) {
return {
request: req => {
if (// my condition is true) {
// do something with the content
// if it's not attached to the request, you could get it from editorState.current
}
return req || $q.when(req);
}
};
}
angular.module('umbraco').factory('myInterceptor', ['$q', interceptor]);
angular.module('umbraco')
.config(function($httpProvider) {
$httpProvider.interceptors.push('myInterceptor');
});
})();
but i need for current page which has been published , this method is showing all the pages i need only the Current page in that the publish event has occured .
in the Performsave of the umbracoController.js you can broadcast an event which can be triggered in a custom plugin.
function performSave(args) {
var deferred = $q.defer();
$scope.page.buttonGroupState = "busy";
contentEditingHelper.contentEditorPerformSave({
statusMessage: args.statusMessage,
saveMethod: args.saveMethod,
scope: $scope,
content: $scope.content,
action: args.action
}).then(function (data) {
//success
init($scope.content);
syncTreeNode($scope.content, data.path);
$scope.page.buttonGroupState = "success";
// REWRITE
// We add an event to enable the language fallback controller
// To reload the current language state
$scope.$broadcast("contentHasBeenSubmited");
deferred.resolve(data);
}, function (err) {
//error
if (err) {
editorState.set($scope.content);
}
$scope.page.buttonGroupState = "error";
deferred.reject(err);
});
return deferred.promise;
}
In your plugin you can inject the editorState where you can get the current one with editorState.getCurrent(). You can check the object to see the properties. Hereby a sample
const languagefallbackController = function ($scope, $timeout, editorState) {
var currentEditorState = editorState.getCurrent();
var contentId = currentEditorState.id;
var alias = currentEditorState.contentTypeAlias;
var somevalue = currentEditorState.tabs[0].properties[0].value.values;
// This event is customly added to the Umbraco.Editors.Content.EditController
// this enable us to reload the control when content has been submitted
$scope.$on("contentHasBeenSubmited", function () {
// do your stuff here
});
});
}
Capture the Umbraco CMS Publish Button Click Event on Client Side Code
I Have Created a Website in that i am having a Section in that i render a blog , but now i want to capture the umbraco publish button event on client side so using that i can post that blog to other sites as well , please help me for this .
Capturing the Publish button click event form umbraco cms side to my client side.
Happy Umbraco... :)
Possibly a few different ways to do this, but I'd try using an AngularJs HTTP interceptor, to capture requests to the /postsave endpoint where the action is publish.
Pretty sure the request includes the complete content item, so you'd be able to check the content type, extract any property values, and do with them whatever you need.
The interceptor is simply a service factory with request and response methods (only interested in request in this example):
HI,
Don't know what the reason is why you want to do this client side?
I tend to do these kind of things server side hooking in to the content service events
https://our.umbraco.org/documentation/Reference/Events/ContentService-Events
Dave
but i need for current page which has been published , this method is showing all the pages i need only the Current page in that the publish event has occured .
Hi Deepak,
It only contains the content items that are being published. In most cases this is only the current item.
It only contains multiple items if the user uses the publish action in the context menu and chooses to publishe child pages as well.
Dave
in the Performsave of the umbracoController.js you can broadcast an event which can be triggered in a custom plugin.
In your plugin you can inject the editorState where you can get the current one with editorState.getCurrent(). You can check the object to see the properties. Hereby a sample
Hi Laurent,
This will work. But there is a downside to this approach. If you upgrade umbraco these changes will be lost.
Luckily there is PR open to have these kind of events fired by code : https://github.com/umbraco/Umbraco-CMS/pull/2640
Dave
is working on a reply...