Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • deepak dubey 4 posts 74 karma points
    May 25, 2018 @ 12:40
    deepak dubey
    0

    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... :)

  • Nathan Woulfe 433 posts 1597 karma points MVP 4x c-trib
    May 26, 2018 @ 04:58
    Nathan Woulfe
    0

    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');
            });  
    })();
    
  • Dave Woestenborghs 3387 posts 11466 karma points MVP 6x admin c-trib
    May 26, 2018 @ 06:54
    Dave Woestenborghs
    0

    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

  • deepak dubey 4 posts 74 karma points
    May 28, 2018 @ 09:17
    deepak dubey
    0

    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 .

  • Dave Woestenborghs 3387 posts 11466 karma points MVP 6x admin c-trib
    May 28, 2018 @ 10:19
    Dave Woestenborghs
    0

    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

  • Laurent Lequenne 121 posts 246 karma points
    May 28, 2018 @ 09:07
    Laurent Lequenne
    0

    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
           });
        });
    }
    
  • Dave Woestenborghs 3387 posts 11466 karma points MVP 6x admin c-trib
    May 28, 2018 @ 10:24
    Dave Woestenborghs
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft