SugarCRM development, custom actions implementation, ActionViewMap configuration, CRM customization

Extending SugarCRM: Using ActionViewMap for Custom Actions

Jordan Hayes - January 14, 2024

Key Takeaways

Aspect Detail
Custom ActionsLearn two approaches to implementing custom actions in SugarCRM: direct view files and ActionViewMap
Implementation MethodsUnderstand the differences between direct view implementation and ActionViewMap registration
Best PracticesFollow 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

  1. 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//views/ directory. Here's an example implementation:

<?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');
    }
}
custom/modules/MyModule/views/view.customaction.php

  1. 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';
custom/Extension/modules/MyModule/Ext/ActionViewMap/custom_action.php

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>
custom/modules/MyModule/tpls/customaction.tpl

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.