SugarCRM 7 — Adding an action to the listview headerpanel

Posted on Sat 25 July 2015 in Tech

This tutorial should show you how to add a custom button/action that will appear across all modules. It's a little similar to this tutorial with a few changes to how the button gets rendered and the actions get called.

1. Adding the button to the headerpanel

Firstly you'll need to create a new folder to store the headerpane actions, so create this folder in the sugarcrm root directory custom/clients/base/views/list-headerpane/. Then create the file list-headerpane.php with this content. This will add a button next to the Create button for all modules.

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

/*
 * Your installation or use of this SugarCRM file is subject to the applicable
 * terms available at
 * [http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/](http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/).
 * If you do not agree to all of the applicable terms or do not have the
 * authority to bind the entity as an authorized representative, then do not
 * install or use this SugarCRM file.
 *
 * Copyright (C) SugarCRM Inc. All rights reserved.
 */

$viewdefs['base']['view']['list-headerpane'] = array(
    'template' => 'headerpane',
    'title' => 'LBL_MODULE_NAME',
    'buttons' => array(
        array(
            'name'    => 'new_button',
            'type'    => 'button',
            'label'   => 'LBL_NEW_BUTTON_LABEL',
            'css_class' => 'btn-secondary',
            'acl_action' => 'list',
            'events' => array(
                'click' => 'list:new_button:fire'
            ),
        ),
        array(
            'name'    => 'create_button',
            'type'    => 'button',
            'label'   => 'LBL_CREATE_BUTTON_LABEL',
            'css_class' => 'btn-primary',
            'acl_action' => 'create',
            'route' => array(
                'action'=>'create'
            )
        ),
        array(
            'name' => 'sidebar_toggle',
            'type' => 'sidebartoggle',
        ),
    ),
);

2. Adding the action hook

To fire this action you'll need to add some code custom/clients/base/views/recordlist/recordlist.js, in the

this.context.on('list:new_button:fire', this.applyFxn, this);

Now populate applyFxn with whatever code you want to run and it will work across every module.

3. Quick Repair and Rebuilt(as always)

Any questions feel free to ask!

Extra tip.

Only want to do this for a single module. Instead of placing the code in custom/clients place it in custom/modules//clients and it should work for just that one module.