Search code examples
pimcore

Add toolbar button for plugin


I know how to add a menu-item at the extras menu by using

pimcoreReady: function (params,broker){
    ...
    toolbar.extrasMenu.add(action);

But what im really looking for is to add a menu-item below the search button, here, Is it possible?

Also, I would like to show this icon only if the user has a certain permission assigned to him, is that possible without changing pimcores core?

Best Regards! /J


Solution

  • This should get you going:

    var user = pimcore.globalmanager.get("user");
    var permissions = user.permissions;
    
    // See what permissions are set - check the console in browser developer tools
    console.log(user.permissions);
    
    if (permissions.indexOf("objects") !== -1) {
      var navigationUl = Ext.get(Ext.query("#pimcore_navigation UL"));
      var newMenuItem = Ext.DomHelper.createDom('<li id="pimcore_menu_new-item" data-menu-tooltip="Your tooltip" class="pimcore_menu_item icon-fork"></li>');
      navigationUl.appendChild(newMenuItem);
      pimcore.helpers.initMenuTooltips();
    
      newMenuItem.onclick = function(){ 
        alert("test") 
      };
    }