Copied to clipboard

Flag this post as spam?

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


  • Dirk De Grave 4532 posts 5977 karma points MVP 3x admin c-trib
    Mar 16, 2017 @ 10:30
    Dirk De Grave
    0

    Adding custom actions on content edit page (not custom context menu)

    Hi all,

    Exploring some ideas here internally and reaching out to this lovely community to get some feedback.

    Essentially, we've got a couple of vorto properties for a specific content type and would love to do some copy/paste from one language to another on editor's request (so doesn't have to do it automagically).

    I was wondering about the best option to implement, and we're thinking about either using the "Save, Save & publish" dropdown button (which would more or less hide the functionality) or add it as a standalone extra button (next to preview button for example)

    Oh, it will involve launching a dialog to specify some settings before the actual action is performed.

    Any tips? Caveats? Do's or don't's? Yay's or nay's, any feedback appreciated!

    --Dirk

  • Dave Woestenborghs 3213 posts 10799 karma points MVP 4x admin c-trib
    Mar 16, 2017 @ 10:42
    Dave Woestenborghs
    100

    Hi Dirk,

    You can do this using angular interceptors. Read this blog by Matt Brailsford to get the idea : http://24days.in/umbraco-cms/2015/umbraco-7-back-office-tweaks/

    For you will want to intercept the content edit view :

    That will look something like this :

    angular.module('umbraco.services').config([
       '$httpProvider',
       function ($httpProvider) {
    
           $httpProvider.interceptors.push(['$q','$injector',function ($q,$injector) {
               return {
                   'request': function (request) {
    
                       // Redirect any requests to built in content delete to our custom delete
                       if (request.url === "views/content/edit.html") {
                           request.url = '/App_Plugins/YourPluginFolder/views/content-edit.html';                      
                       }
    
                       return request || $q.when(request);
                   }
               };
           }]);
    
       }]);
    

    This will intercept all calls to the content edit view and replace the edit view with your own.

    In your own you can copy the markup of the built in edit view and add your button. Also you need to change the ng-controller directive to point to your own controller.

    Then in your controller you can do this :

    angular.module('umbraco').controller('YourControllerName',
        ['$scope', '$controller',
        function ($scope, $controller) {
            // inherit core edit controller
            angular.extend(this, $controller('Umbraco.Editors.Content.EditController', { $scope: $scope }));
    
            // add your logic for handling button click here
        }]);
    

    The important line here is

    angular.extend(this, $controller('Umbraco.Editors.Content.EditController', { $scope: $scope }));
    

    This will make the scope and functions from the core controller available in your controller...like inheriting a class in C#. So all core functionality keeps working.

    Only downside is that when you upgrade umbraco it's possible that it breaks because the core view can change.

    Dave

  • Dirk De Grave 4532 posts 5977 karma points MVP 3x admin c-trib
    Mar 16, 2017 @ 10:48
    Dirk De Grave
    0

    I get the gist, was reading up on Matt's article, just was exploring some ideas and options before we decide to go with route a or b

    Copying the view is a trade off indeed, but we intend to do it anyway for other parts of the system, so we're aware of the possible upgrade trap.

  • Dave Woestenborghs 3213 posts 10799 karma points MVP 4x admin c-trib
    Mar 16, 2017 @ 10:51
    Dave Woestenborghs
    0

    But this idea can also be applied to the Vorto view. So you will have the option in the vorto editor.

    This way you don't override any core things, but only Vorto...maybe it's easier to maintain when doing upgrades

  • Dirk De Grave 4532 posts 5977 karma points MVP 3x admin c-trib
    Mar 16, 2017 @ 10:54
    Dirk De Grave
    0

    Agree, and we already have a custom vorto implementation (until Matt wants to merge in the PR (Are you listening Matt?)) ;-)

  • Ravi Motha 278 posts 487 karma points MVP 3x c-trib
    Mar 16, 2017 @ 10:42
    Ravi Motha
    0

    so the action you want is something the user has to ask for or be notified of??

    My temptation would be to have it as a separate "thing", ie button , and actions, because then you can specify your own rules

  • Dirk De Grave 4532 posts 5977 karma points MVP 3x admin c-trib
    Mar 16, 2017 @ 10:47
    Dirk De Grave
    0

    no, user initiates the action, and has to provide some settings (in our specific example, specity what source and destination language through a custom view - don't see any issues here) and perform the actual action

Please Sign in or register to post replies

Write your reply to:

Draft