Forked from jasondavis/SugarCRM Custom Fields on Detail View
Last active
July 26, 2022 20:24
-
-
Save rajeshvaya/32584d21a1e772d9ca20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$module_name = 'ModuleNameHere'; | |
$_object_name = 'ModuleNameHere'; | |
$viewdefs[$module_name] = array( | |
'DetailView' => array( | |
'panels' => array( | |
'default' => array( | |
0 => array( | |
0 => array( | |
'name' => 'name', | |
'label' => 'LBL_PROJE_WEB_PROJECTS_NAME', | |
), | |
1 => 'proje_web_projects_number', | |
), | |
1 => array( | |
0 => 'date_entered', | |
1 => array( | |
'name' => 'status', | |
'label' => 'LBL_STATUS', | |
'customCode' => '{$STATUS}', | |
), | |
), | |
2 => array( | |
0 => array( | |
'name' => 'date_completed', | |
'label' => 'LBL_DATE_COMPLETED', | |
'customCode' => '{$DATE_COMPLETED}', | |
), | |
1 => 'priority', | |
), | |
), | |
), | |
), | |
); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add a Custom Field to a SugarCRM Module and execute custom PHP code in that field on the DetailView. | |
Is a 2 step process. | |
1) Have to modify the detailviewdefs.php file and add a CustomCode to your field in this file... | |
/custom/modules/<MODULE-NAME_FOLDER>/metadata/detailviewdefs.php | |
set a variable in a customCode key/value like this... | |
'customCode' => '{$STATUS}', | |
2) Have to copy your /modules/<MODULE-NAME_FOLDER>/views/view.detail.php file to | |
/custom/modules/<MODULE-NAME_FOLDER>/views/view.detail.php | |
In that file you can Assign Smarty template tags like this... | |
$this->ss->assign('STATUS', $somaeVariable); | |
NOTICE: STATUS IS THE SAME NAME OF THE VARIBALE WE SET IN THE FILE ABOVE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); | |
class ModuleNameHereViewDetail extends ViewDetail{ | |
public function ModuleNameHereViewDetail(){ | |
parent::ViewDetail(); | |
} | |
public function display(){ | |
// Include our own JavaScript or CSS file into the page | |
echo '<script type="text/javascript" src="custom/modules/<ModuleNameHere>/js/our_custom_js_file.js"></script>'; | |
// Print JavaScript directly to page | |
echo '<script type="text/javascript">var foo = "bar";</script>'; | |
$someVariable = 'something that generates out field output will go here'; | |
// Assign custom "Status" value to Smarty template | |
$this->ss->assign('STATUS', $somaeVariable); | |
// Assign custom Date Completed value if it is empty | |
if(isset($this->bean->date_completed) && $this->bean->date_completed != ''){ | |
$this->ss->assign('DATE_COMPLETED', $this->bean->date_completed); | |
}else{ | |
$this->ss->assign('DATE_COMPLETED', '---------'); | |
} | |
// Get Total Open and Closed Tasks Count | |
$this->bean->load_relationship('proje_web_projects_proje_web_project_tasks'); | |
$closed_tasks_count = 0; | |
$open_tasks_count = 0; | |
foreach ($this->bean->proje_web_projects_proje_web_project_tasks->getBeans() as $proje_web_project_tasks) { | |
if($proje_web_project_tasks->status === 'Open' || $proje_web_project_tasks->status === 'In_Progress'){ | |
$open_tasks_count = $open_tasks_count+1; | |
}else if($proje_web_project_tasks->status === 'Completed'){ | |
$closed_tasks_count = $closed_tasks_count+1; | |
} | |
} | |
// Open Count | |
if($open_tasks_count < 10){ | |
$open_tasks_count = ' <span id="open-count">'.$open_tasks_count.'</span> Open Tasks<br> '; | |
}else{ | |
$open_tasks_count = '<span id="open-count">'.$open_tasks_count.'</span> Open Tasks<br> '; | |
} | |
// Closed count | |
if($closed_tasks_count < 10){ | |
$closed_tasks_count = ' <span id="closed-count">'.$closed_tasks_count.'</span> Closed Tasks<br> '; | |
}else{ | |
$closed_tasks_count = '<span id="closed-count">'.$closed_tasks_count.'</span> Closed Tasks<br> '; | |
} | |
// Assign Project Stats | |
$project_stats = $closed_tasks_count . $open_tasks_count . $documents_count; | |
$this->ss->assign('PROJECT_STATS', $project_stats); | |
parent::display(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment