Skip to content

Instantly share code, notes, and snippets.

@matthewpoer
Created March 27, 2014 19:20
Show Gist options
  • Save matthewpoer/9815907 to your computer and use it in GitHub Desktop.
Save matthewpoer/9815907 to your computer and use it in GitHub Desktop.
When installing a package, maybe you need to add some buttons to a modules detail or edit view? Maybe you'd like to add your button without, you know, wiping out existing customization to the system's layout? Here's how you'd do that with a post_install script. Simply place this within your module's directory at /scripts/post_install.php, zip it…
<?php
function post_install(){
// define our new button that will copy into detailviewdefs.php
$button = array(
'customCode' => '<input type=\'button\' title=\'Create Payments\' onclick=\'this.form.action.value=\\\'CreatePayments\\\';\' />',
'sugar_html' => array(
'type' => 'submit',
'value' => 'Create Payments',
'htmlOptions' => array(
'class' => 'button',
'id' => 'CreatePaymentsButton',
'title' => 'Create Payments',
'onclick' => 'this.form.action.value=\'CreatePayments\';',
),
),
);
// load and use ParserFactory to add the button to the current layout
require_once('modules/ModuleBuilder/parsers/ParserFactory.php');
$parser = ParserFactory::getParser('detailview', 'Contacts');
array_push($parser->_viewdefs['templateMeta']['form']['buttons'], $button);
$parser->handleSave(false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment