<![CDATA[ Adding icon to the Resource Toolbar - MODX Community Forums]]> https://forums.modx.com/thread/?thread=87107 <![CDATA[Adding icon to the Resource Toolbar]]> https://forums.modx.com/thread/87107/adding-icon-to-the-resource-toolbar#dis-post-479882
Has anyone else managed to do this before?

Here's the related code that does not seem to do much:

switch ($modx->event->name) {
    case 'OnResourceToolbarLoad':
        $modx->log(modX::LOG_LEVEL_ERROR, 'Triggered on OnResourceToolbarLoad');
        $action = (isset ($modx->actionMap) && isset($modx->actionMap['resource/create']) ) ? $modx->actionMap['resource/create'] : 'resource/create';
        $scriptProperties['items'][] = array(
            'icon' => 'assets/components/moregallery/mgr/img/picture.png',
            'tooltip' => 'add new gallery',
            'handler' => 'new Function("this.redirect(\"index.php?a='.$action.'&class_key=mgResource\");");'
        $items[] = array(
            'icon' => 'assets/components/moregallery/mgr/img/picture.png',
            'tooltip' => 'add new gallery',
            'handler' => 'new Function("this.redirect(\"index.php?a='.$action.'&class_key=mgResource\");");'

The logging statement ends up in the error log as expected, so the code is being triggered.

The code in the core (resource/gettoolbar processor) looks like this:
    'items' => &$items,

return $this->modx->error->success('',$items);

I would expect from that code that changing the $items array in the plugin should change the toolbar. That didn't work, so I also added it via $scriptProperties['items'], thinking that might work instead, but no dice there either.

Am I looking at this completely wrong, or is the pass-by-reference way of working with plugin variables completely broken?]]>
markh Oct 10, 2013, 03:02 PM https://forums.modx.com/thread/87107/adding-icon-to-the-resource-toolbar#dis-post-479882
<![CDATA[Re: Adding icon to the Resource Toolbar (Best Answer)]]> https://forums.modx.com/thread/87107/adding-icon-to-the-resource-toolbar#dis-post-480039
switch ($modx->event->name) {
    case 'OnManagerPageBeforeRender':
         * @var modManagerController $controller
        if (!$modx->getOption('moregallery.add_icon_to_toolbar', null, true)) {
MODx.on('ready', function() {
    var tree = Ext.getCmp('modx-resource-tree'),
        tb = tree.getTopToolbar();

    setTimeout(function() {
        tb.insertButton(4, {
            icon: '/assets/components/moregallery/mgr/img/picture.png',
            tooltip: 'Add Gallery',
            handler: function() {
                var action = (MODx.action && MODx.action['resource/create']) ? MODx.action['resource/create'] : 'resource/create';
                MODx.loadPage(action, 'class_key=mgResource');
    }, 150);
markh Oct 11, 2013, 01:21 PM https://forums.modx.com/thread/87107/adding-icon-to-the-resource-toolbar#dis-post-480039
<![CDATA[Re: Adding icon to the Resource Toolbar]]> https://forums.modx.com/thread/87107/adding-icon-to-the-resource-toolbar#dis-post-479904

Thanks for the example code, that'll save me some time!]]>
markh Oct 10, 2013, 07:17 PM https://forums.modx.com/thread/87107/adding-icon-to-the-resource-toolbar#dis-post-479904
<![CDATA[Re: Adding icon to the Resource Toolbar]]> https://forums.modx.com/thread/87107/adding-icon-to-the-resource-toolbar#dis-post-479898
Never did that (wasn't even aware of the event), but i also failed at adding it via PHP.
Another option could be via ExtJS wink

 * @var modX $modx
 * @var array $scriptProperties
 * @event OnManagerPageBeforeRender

$modx->controller->addHtml('<script>Ext.onReady(function() {
    var tree = Ext.getCmp("modx-resource-tree");
    var tb = tree.getTopToolbar();
            icon: "404.png",
            tooltip: "Tip tip ?",
            handler: function() {

return '';

Hope that will help]]>
romain Oct 10, 2013, 06:41 PM https://forums.modx.com/thread/87107/adding-icon-to-the-resource-toolbar#dis-post-479898