I am using SuiteCRM 7.4.3 and need to include two files (a PHP file and a JS file) into the whole project instance. What are the best practices in this situation? Where should I copy the source files and where do I include them?
-
What would be the reason to adding these files? Are you extending the functionality i.e. adding logic_hooks or just to include the JS in the overall SuiteCRM instance? – MissAran Feb 17 '16 at 12:28
-
@MissAran I want use this [JalaliDate](https://github.com/sallar/jDateTime) for Persian language. – Amirhossein Rzd Feb 17 '16 at 12:33
-
Use composer for php, and bower/npm for JS library. – k0pernikus Mar 08 '16 at 14:53
-
Jalali date also mentions composer in its readme: php composer.phar require "sallar/jdatetime":"dev-master" – k0pernikus Mar 08 '16 at 14:54
2 Answers
SuiteCRM uses its own TimeDate class which from the look of it you will need to extend to create your own (this JalaliDate). Honestly, I don't know how you could implement this without affecting the core SuiteCRM massively.
However, the files you will need to look at are include/TimeDate.php (which is the class Suite uses for all its time formatting). We always recommend that you try to make everything upgrade safe i.e. everything is within custom folder - however, from the look of this it won't be.
But, what I usually do when I include SDK of other applications I place it in custom/include/ and then whenever I need it I link it from there.

- 125
- 9
-
Thank you. I will try to work in the custom folder and let you know the result. – Amirhossein Rzd Feb 18 '16 at 05:52
If you need to use a javascript file SuiteCRM, You can use create a custom view that spits out the "script tags".
class CustomModuleViewSomething extends ViewEdit
{
function display(){
$this->ev->process();
$scripts = array();
$scripts[] = '<script src="javascript1.js"></script>';
$scripts[] = '<script src="javascript2.js"></script>';
$scripts[] = '<script src="javascript3.js"></script>';
echo $this->ev->display($this->showTitle) . implode($scripts);
}
}
I have a gist which depends on moment.js in order to process dates in JS. this is useful when you need process dates on the client side dates.
/**
* returns js Date() from a date that is in the users format
* @depends momentjs library
* @param datestr
* @returns {*|Date}
*/
function toDate(datestr) {
var $format = "", $splitformat = ["","",""], $dbformat = ["","",""];
// Get user preferences date format
$format = cal_date_format
$format = $format.toUpperCase();
$format = $format.replace('%D', 'DD')
$format = $format.replace('%M', 'MM')
$format = $format.replace('%Y', 'YYYY')
// return js date
return moment(datestr, $format).toDate()
}
The better way to handle dates is to create an action in a customController:
class CustomModuleController extends SugarController {
function action_save() {
global $timedate;
$field = "date_entered";
$timedate->fromString($this->bean->$field);
$this->bean->save(!empty($this->bean->notify_on_save));
}
}

- 718
- 4
- 18