Customizing Buttons on the Quote Detail View

sugarcrmdevelopers —  September 24, 2012

If you’ve ever tried to add buttons to the top of a Detail View, you know it’s not a difficult process. Typically a simple adjustment to the MetaData is all that is needed. Changes are straight-forward and upgrade-safe. But that’s not the case with the Quotes module.The Quotes module, because it must invoke different sets of buttons depending on which PDF engine the system uses, re-defines the button array in the view.detail.php instead of the metadata. This makes customization of the button array difficult, because you have to extend the QuotesViewDetail class (using CustomQuotesViewDetail), specifically the display() function. Display of course calls the view directly and so you don’t really have access to override the overridden button array without copy-and-pasting the entire function.

This of course works fine and is technncially upgrade-safe, but it isn’t upgrade-aware. That means that if the original QuotesViewDetail is updated in a later version to take advantage of some new functionality or bugfix our custom class will still be preferred (good) but won’t recognize the potentially-important changes (bad). This happend recently when SugarCRM refactored the Quotes EditView related JavaScripts, making the entire set of functions a “QuotesManager” object instead of a more simple (but less organized) set of  miscellaneous functions within a single file.

In the example I’m working on tonight, I’ve copied the file as described above, I’ve adjusted the end of the display method to the following before invoking parent::display() (which will actually echo out the content of the page).

$new_array = array();
$MyNewCustomCodeButton = "<input type='button' onclick='SomeAction();' value='Click me' />";

$new_array[] = $this->dv->defs['templateMeta']['form']['buttons'][0]; // EDIT
$new_array[] = $this->dv->defs['templateMeta']['form']['buttons'][1]; // DUPLICATE
$new_array[] = $this->dv->defs['templateMeta']['form']['buttons'][2]; // DELETE
$new_array[] = array('customCode' => $MyNewCustomCodeButton);
$new_array[] = $this->dv->defs['templateMeta']['form']['buttons'][3]; // quote2opp
$new_array[] = $this->dv->defs['templateMeta']['form']['buttons'][4]; // quote2pdf
$this->dv->defs['templateMeta']['form']['buttons'] = $new_array;


A word of caution, the button you add will not being loaded into the existing form due to a metadata variable CloseFormBeforeCustomButtons. You can unset this variable, but it’ll ruin ability to use the PDF buttons. If you need to go this route, rReview the code in /include/DetailView/header.tpl. If you need to tie into the first form used by EDIT, DUPLICATE and DELETE buttons, you’ll do best to build the button and attach it to the form using JavaScript.