Hello @RalfBecker,
thanks for your reply, it helped me search at the right place. The different class name currency2 at the commented out code was a desperate action while trying to find out why things where not working… Nevertheless I actually had made 2 similar mistakes:
- I had forgotten the “.inc.” letters in the filename of my class file, so it was not autoloaded.
- I made an error when using the Api\Framework::includeJS("/$app/$file") function you mentioned.
After that I can confirm that moving a widget to a custom application is straight forward. Let’s say
- the application is called “achelper”,
- the widget is called “currency”
- then the php class should be named achelper_widget_currency and the classfile class.achelper_widget_currency.inc.php
- the js file is named et2_widget_currency.js
Steps:
- In the setup.inc.php of the achelper application add the ‘etemplate2_register_widgets’ hook to a static function:
$setup_info[‘achelper’][‘hooks’][‘etemplate2_register_widgets’] = ‘achelper_hooks::widgets’;
- In the achelper_hooks class add a static function, in this case named widgets as defined in setup.inc.php returning the widget class:
/**
Returns a list of custom widgets classes for etemplate2
*/
public static function widgets()
{
return [‘achelper_widget_currency’];
}
- Put the js file ‘et2_widget_currency.js’ in the js folder of the achelper app:
/achelper/js/et2_widget_currency.js
- Include the js file in the constructor of the php class:
**
eTemplate currency textbox
Supports formatting for decimal & thousands, and currency prefix/suffix
*/
class achelper_widget_currency extends Etemplate\Widget
{
public function __construct($xml=’’) {
Api\Framework::IncludeJS("/achelper/js/et2_widget_currency.js");
parent::__construct($xml);
}
Including in the beforeSendToClient() function works also fine, I don’t know which is the better place…
Now my last question about this is how the et2_widget_currency.js can be included in the min.js files. I included it in the Gruntfile.js in the Egroupware root and ran “grunt” but my widget is still using the uncompressed version.
Thanks again everyone and Best Regards,
Alex