Extending SugarCRM: Using ActionViewMap for Custom Actions
Key Takeaways
Aspect | Detail |
---|---|
Custom Actions | Learn two approaches to implementing custom actions in SugarCRM: direct view files and ActionViewMap |
Implementation Methods | Understand the differences between direct view implementation and ActionViewMap registration |
Best Practices | Follow upgrade-safe practices for maintaining customizations through system updates |
Understanding Actions in SugarCRM
Actions in SugarCRM represent specific tasks or operations within modules, such as viewing, editing, or deleting records. Each action corresponds to a view that defines the user interface and system behavior. While SugarCRM provides standard actions like detailview, editview, and listview, custom actions enable developers to extend functionality for specific business needs.
Creating Custom Actions: Two Approaches
- Adding a Custom View Directly
A simple way to implement a custom action is to add a new view file directly in the custom/modules/
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/MVC/View/views/view.detail.php');
class MyModuleViewCustomAction extends ViewDetail
{
function display()
{
// Custom logic here
echo 'This is a custom action!';
// Optionally render a template
$this->ss->display('custom/modules/MyModule/tpls/customaction.tpl');
}
}
- Using ActionViewMap Registration
The ActionViewMap approach provides more control over custom actions, especially for non-standard action names. Here's how to implement it:
<?php
$action_view_map['customaction'] = 'customaction';
Why Choose ActionViewMap?
ActionViewMap offers several advantages for implementing custom actions:
- Explicit routing control for non-standard action names
- Better management of custom action mappings
- Ability to override core actions safely
- Improved upgrade safety through proper extension practices
Template Integration
{* Smarty template for custom action *}
<div class="custom-action-container">
<h2>{$MOD.LBL_CUSTOM_ACTION_TITLE}</h2>
<div class="custom-content">
{$customData}
</div>
</div>
Conclusion
Using ActionViewMap provides a robust way to extend SugarCRM's functionality while maintaining upgrade safety and code organization. Whether you choose direct view implementation or ActionViewMap registration depends on your specific needs, but following these patterns ensures your customizations remain maintainable and scalable.