Sugarcrm支持产品指南糖开发人员糖开发人员指南11.0建筑学逻辑钩子模块钩子before_save.

before_save.

概述

The before_save. logic hook executes before a record is saved.

定义

function before_save($bean, $event, $arguments){}

争论

名称 类型 描述
豆角,扁豆 目的 豆角,扁豆对象
事件 细绳 当前的事件
争论 大批 与活动有关的其他信息
争论.check_notify. 布尔基 是否发送通知
争论.isupdate. 布尔基

记录是否是新创建的

  • true =这是对现有记录的更新
  • false =新创建的记录

考虑

  • For modules that contain a user-friendly record ID (e.g. the case_number field for the Cases module), the value of that field is not available for a before_save. call. This is because this business logic has yet to be executed.
  • Calling save on the bean in this hook will cause an infinite loop if not handled correctly. (i.e: $bean->save())

例子

使用扩展框架创建逻辑钩

./custom/extension/modules/<module>/Ext/LogicHooks/<file>.php

<?php

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

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

        //The PHP file where your class is located.
        'custom/modules/<module>/before_save_class.php.',

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

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

?>

./custom/modules/<module>/before_save_class.php.

<?php

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

    class before_save_class
    {
        function before_save_method($bean, $event, $arguments)
        {
            //logic
        }
    }

?>

创建核心逻辑挂钩

在糖6.3.x之前,只能使用以下方法创建逻辑钩。请注意,此方法仍然有效,但在构建插件时不建议使用与现有自定义相冲突时。

./custom/modules/<module>/logic_hooks.php

<?php

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

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

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

      //The PHP file where your class is located.
      'custom/modules/<module>/before_save_class.php.', 

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

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

?>

./custom/modules/<module>/before_save_class.php.

<?php

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

   class before_save_class
   {
      function before_save_method($bean, $event, $arguments)
      {
         //logic
      }
   }

?>

最后修改:2021-02-17 02:44:13