We are always on the outlook to help provide our developers easier and more upgrade-safe methods to make customizations to SugarCRM. Today I’m going to show you how to do one customization we added in Sugar 6, as a response from a suggestion we had brought up by a partner of ours back at SugarCon this past spring. It also came up in the forums recently, so I felt it was appropriate to bring it up on the developer blog today
This customization involves the action items that are at the top of the ListView records and how to add your own items to the list. Prior to Sugar 6 were a series of buttons along right above the header, but we changed in Sugar 6 to be a dropdown menu as shown below.
So to enable this, we added a new property to the ListViewDisplay class named $actionsMenuExtraItems, which is an array of HTML elements to add to this menu list. The elements are pure HTML, so you can easily build the item and the action to take when the item is clicked. The best way to define these items is by overriding the default list view and defining it yourself in the custom directory. So if we wanted to add a new action menu item “Send records to a new view!” item to the Accounts module menu, we could do it as follows below.
The first part of this customization is to create the action menu item, which we build in the buildMyMenuItem() method. The menu item is a simple anchor element, where we set the onclick property of it populate the uid form value ( using the sugarListView.get_checks() call ), then check to make sure at least one record is checked ( by making sure the sugarListView.get_checks_count() is greater than zero ) and then finally by setting the action we will redirect to and submitting the form to it.
The next half is to create an action to receive the form post from the above menu item. We can do this easily with a custom Accounts controller, as shown below.
The list of records that were checked in the listview is provided by a comma delimited list in the uid request variable. We can use explode() to make this into an array, and then iterate over it to display the records sent to it.
You can use this example as the basis for adding all sorts of action menu items to listviews.