问题
I've developed a javascript file that I want to include in a package, and I see that I can add it with a custom editviews.php file. That works fine. However, I wish to make it easy for my counterpart to install it. I created a file in the custom/extension/modules/leads/vardefs/ folder with the following contents (and did a quick repair):
$viewdefs['Leads']['EditView']['templateMeta']['includes'][]=array('file'=>'custom/modules/mme_form_js_functions.js');
$viewdefs['Leads']['QuickCreate']['templateMeta']['includes'][]=array('file'=>'custom/modules/mme_form_js_functions.js');
That does not seem to work, so if anyone has a quick suggestion of how to do this using the extension framework, I would love to know the answer without having to unravel the sugar php code.
回答1:
Did you do a Quick repair and rebuild after you made these changes? That would be required. Another thing is that capitalization counts in SugarCRM and your file is in the wrong place, it should be
custom/Extension/modules/Leads/Ext/Vardefs/YourFileName.php
回答2:
Here's how I ended up doing it (SuiteCRM 7.10):
First, register an after_ui_frame
application hook, i.e. create custom/Extension/application/Ext/LogicHooks/myhooks.php
containing something like:
<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['after_ui_frame'] = Array();
$hook_array['after_ui_frame'][] = Array(99, 'Add my custom js',
'custom/Extension/application/mycustomizations.php', 'MyHooks', 'add_my_js');
Then create custom/Extension/application/mycustomizations.php
and add your javascript file (you can decide to add it only to certain modules/actions):
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not a valid entry point');
class MyHooks {
function add_my_js($event, $args){
if ($_REQUEST['module'] == 'Leads' && $_REQUEST['action'] == 'EditView') {
echo '<script type="text/javascript" src="custom/Extension/application/mycustom.js"></script>';
}
}
}
Finally, do a Quick repair and rebuild
.
来源:https://stackoverflow.com/questions/18214131/adding-javascript-include-using-extension