Recently one of our customers wished for the follow and favorite logic to be avaliable to them in a custom module. By seaching through the sugar core we identified various modifications to achive this functionality in custom modules.
The first step is to add the vardef templates ‚favorite‘ and ‚following‘ to your module. You can do this by modifying the ‚vardefs.php‘ in the <sugar-instance>/modules/<your-module> directory.
Just add ‚favorite‘ and ‚following‘ to the last line in the file like this:
VardefManager::createVardef('<your-module>','<your-module>', array('basic','team_security','assignable', 'favorite', 'following'));
At the beginning of this file there’s the element ‚activity_enabled‘ we need to turn this on for the following button to work:
'activity_enabled' => true,
If you are not comfortable to work in the sugar core, you can also do this with the Extension Framework by adding a file (any name with .php extension) to the <sugar-instance>/custom/Extension/modules/<your-module>/Ext/Vardefs directory and adding the following code:
<?php $dictionary['<your-module>']['activity_enabled'] = true; $dictionary['<your-module>']['uses'] = 'favorite'; $dictionary['<your-module>']['uses'] = 'following';
The next step is to make sure the favorite and follow buttons are included in the record view (The Sugar Module Builder does this automatically). In the <sugar-instance>/modules/<your-module>/clients/base/views/record/record.php file look for the panels array and the first entry named panel_header. In there the last two elements should be the follow and favorite button.
After this just do a ‚Quick Repair and Rebuild‘ and your follow and favorite buttons should work! If you have any questions regarding this guide or need support with your sugarcrm instance please feel free to contact us.