SugarCRM SupportDocumentationSugar DeveloperSugar Developer Guide 8.0ArchitectureLogic HooksAPI Hooksbefore_respond

before_respond

Overview

The before_respond hook executes before the v10+ REST Service call returns data to the user.

Definition

function before_respond($event, $response){}

Arguments

Name Type Description
event String The name of the logic hook event
response Object The RestResponse Object

Considerations

  • This is a global logic hook where the logic hook reference must be placed in ./custom/modules/logic_hooks.php.
  • It is not advised to remove or unset any data. Sugar may be using this data and it can adversely affect your instance.
  • This hook should not be used for any type of display output.
  • This hook should be used when you want to add data to all API responses. If you are looking to modify data received from one specific endpoint, It is a much better approach to override that specific endpoint rather than to use this logic hook.

Change Log

Version Note
7.0.0RC1 Added before_respond hook

Example

./custom/modules/logic_hooks.php

<?php

    $hook_version = 1;
    $hook_array = Array();

    $hook_array['before_respond'] = Array();
    $hook_array['before_respond'][] = Array(
        //Processing index. For sorting the array.
        1, 

        //Label. A string value to identify the hook.
        'after_routing example', 

        //The PHP file where your class is located.
        'custom/modules/logic_hooks_class.php',

        //The class the method is in. 
        'logic_hooks_class',

        //The method to call. 
        'before_respond_method' 
    );

?>

./custom/modules/logic_hooks_class.php

<?php

    if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class logic_hooks_class
    {
        function before_respond_method($event, $response)
        {
            //logic
        }
    }

?>

 

Last modified: 2018-04-26 03:57:24