My environment:
SuiteCRM Version used: 7.10.4
Chrome Version 66 (64-bit)
MySQL 5.6, PHP 7.1.12
macOS Sierra 10.12.3
Up until now I haven’t had much reason to create any custom views. But we have a desire to implement a process wherein there is a ‘pre-sale’ check that is done before an opportunity is entered.
Here is what I have so far:
First I created: custom/modules/Opportunities/controller.php
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/MVC/Controller/SugarController.php');
class OpportunitiesController extends SugarController {
function action_preCheck(){
$this->view = 'preSaleCheck';
}
}
?>
Next I created a file in: custom/include/MVC/Controller/action_view_map.php
<?php
$action_view_map['preCheck'] = 'PreSaleCheck';
?>
Next I created a file in custom/modules/Opportunities/view.preSaleCheck.php
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once("include/MVC/View/views/view.edit.php");
require_once('custom/include/utilities.php');
class ViewPreSaleCheck extends ViewEdit
{
public function preDisplay()
{
if (!$this->bean->ACLAccess('edit')) {
ACLController::displayNoAccess();
sugar_die('');
}
$metadataFile = 'custom/modules/Opportunities/metadata/presalecheckdefs.php';
$customContinue = '<input title="" accesskey="i" class="button primary"
onclick="
var _form = document.getElementById(\'EditView\');
_form.return_module.value=\'Opportunities\';
_form.return_action.value=\'DetailView\';
_form.action.value=\'EditView\';
SUGAR.ajaxUI.submitForm(_form);" type="button" name="Edit" id="edit_button" value="Continue" style="display:none;">';
$this->ss->assign('CUSTOM_CONTINUE_BUTTON', $customContinue);
$this->ev = new EditView();
$this->ev->ss =& $this->ss;
$this->ev->view = "PreSaleCheck";
$this->ev->setup($this->module, $this->bean, $metadataFile, 'include/EditView/EditView.tpl', true, 'presalecheckdefs');
}
public function display(){
echo createModal('PRE-SALE CHECK', '<br><h2 id="modal_text"></h2><br>', 'OK', 'false');
echo '<div class="moduleTitle">
<h2>PRE-SALE CHECK</h2>
</div>';
$this->ev->process();
echo $this->ev->display();
}
}
Finally, I created a file in custom/modules/Opportunities/metadata/presalecheckdefs.php
<?php
$viewdefs ['Opportunities'] =
array (
'PreSaleCheck' =>
array (
'templateMeta' =>
array (
'form' =>
array (
'buttons' =>
array (
0 => array(
'customCode' => '<input title="" class="button primary" type="button" name="button" value="CHECK" id="preCheck">'
),
1 => array(
'customCode' => '{$CUSTOM_CONTINUE_BUTTON}'
),
2 => 'CANCEL',
),
),
'maxColumns' => '2',
'widths' =>
array (
0 =>
array (
'label' => '10',
'field' => '30',
),
1 =>
array (
'label' => '10',
'field' => '30',
),
),
'useTabs' => false,
'tabDefs' =>
array (
'LBL_EDITVIEW_PANEL2' =>
array (
'newTab' => false,
'panelDefault' => 'expanded',
),
'LBL_PANEL_ASSIGNMENT' =>
array (
'newTab' => false,
'panelDefault' => 'expanded',
),
),
'syncDetailEditViews' => false,
),
'panels' =>
array (
'lbl_editview_panel2' =>
array (
0 =>
array (
0 =>
array (
'name' => 'contact_name_c',
'studio' => 'visible',
'label' => 'LBL_CONTACT_NAME',
),
),
1 =>
array (
0 =>
array (
'name' => 'joint_name_c',
'studio' => 'visible',
'label' => 'LBL_JOINT_NAME',
),
),
5 =>
array (
0 =>
array (
'name' => 'writing_number_c',
'studio' => 'visible',
'label' => 'LBL_WRITING_NUMBER',
),
),
6 =>
array (
0 =>
array (
'name' => 'split_pr_c',
'studio' => 'visible',
'label' => 'LBL_SPLIT_PR',
),
),
),
'LBL_PANEL_ASSIGNMENT' =>
array (
0 =>
array (
0 =>
array (
'name' => 'product_detail_c',
'studio' => 'visible',
'label' => 'LBL_PRODUCT_DETAIL',
),
),
1 =>
array (
0 =>
array (
'name' => 'raise_c',
'studio' => 'visible',
'label' => 'LBL_RAISE',
),
),
),
),
),
);
;
?>
Then I navigate to localhost:8888/admin/index.php?module=Opportunities&action=preCheck and I get this:
Any idea why the buttons from the metadata are not appearing? Commenting out the section of code in presalecheckdefs.php does not cause them to appear and an inspection of the html reveals that there doesn’t seem to be anything wrapping around the panels, the form metadata is not coming in.