Sugarcrm支持产品指南糖开发人员糖开发人员指南10.0建筑学延期Logichooks.

Logichooks.

概述

The Logichooks. extension adds actions to specific events such as, for example, before saving a bean. For more information on logic hooks in Sugar, please refer to the 逻辑钩子 documentation.

特性

可用以下扩展属性。有关更多信息,请参阅 延期财产 documentation.

财产 价值
扩展范围 全部 - 应用& Module
糖变量 $ hook_array.
扩展目录

应用程序 - ./custom/extension/pplication/ext/logichooks/

模块 - ./custom/extension/modules/<module>/Ext/LogicHooks/

编译扩展文件

应用程序 - ./custom/pplication/ext/logichooks/logichooks.ext.php.

模块 - ./custom/modules/<module>/ bext/logichooks/logichooks.ext.php.

清单installdef. $ installdefs ['hookdefs']

执行

以下部分说明了为糖实例实现自定义的各种方式。

文件系统

When working directly with the filesystem, you can create a file in ./custom/extension/pplication/ext/logichooks/ to add a new logic hook to the application. The following example will create a new before_save logic hook that executes for all modules:

./custom/extension/pplication/ext/logichooks/<file>.php

<?php

    $hook_array['before_save'][] = Array(
        1, 
        'Custom Logic', 
        'custom/application_hook.php', 
        'ApplicationHookConsumer', 
        'before_method'
    );

接下来,创建挂钩类:

./custom/application_hook.php.

<?php

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

    class ApplicationHookConsumer
    {
        function before_method($bean, $event, $arguments)
        {
            //logic
        }
    }

?>

最后,导航到管理员> Repair > Quick Repair and Rebuild. The system will then rebuild the extensions and the customizations will be compiled into ./custom/application/ bext/logichooks/logichooks.ext.php.. Your logic hook will run before saving records in any module.

模块可加载包装

When building a module loadable package, you can use the $ installdefs ['hookdefs'] index to install the extension file.

installdef属性

名称 类型 描述
细绳 要安装的文件的基础路径。
to_module. 细绳 将安装文件的模块的键。

The example below demonstrates the proper install definition that should be used in the ./manifest.php. 文件 in order to add the Action View Map file to a specific module. You should note that when using this approach, you still need to use the $installdefs['copy'] index for the hook class file, however Sugar will automatically execute Rebuild Extensions to reflect the new logic hook in the system.

./manifest.php.

<?php

$manifest = array(
    ...
);

$installdefs = array(
    'id' => 'actionView_example',
    'hookdefs' => array(
        array(
            'from' => '<basepath>/Files/custom/Extension/application/Ext/LogicHooks/<file>.php',
            'to_module' => 'application',
        )
    ),
    'copy' => array(
        array(
            'from' => '<basepath>/Files/custom/application_hook.php',
            'to' => 'custom/application_hook.php',
        ),
    )
);

Alternatively, you may use the $installdefs['copy'] index to copy the file. When using this approach, you may need to manually run repair actions such as a Quick Repair and Rebuild. For more information on the $installdefs['copy'] index and module-loadable packages, please refer to the 介绍清单 page.

替代installdef.

Although not recommended, you could utilize the $installdefs['logic_hooks'] index to deploy a logic hook to the system. Please note that there are a couple caveats to this installation method:

  • The $installdefs['logic_hooks'] index method only works for module-based logic hooks.
  • The $installdefs['logic_hooks'] index method installs to ./custom/modules/<module>/logic_hooks.php, which is not part of the Extension framework.

特性

名称 类型 描述
模块 细绳 要安装逻辑挂钩的模块的键。
细绳 要安装的逻辑挂钩类型。
命令 整数 逻辑挂钩应该运行的数字。
描述 细绳 要安装的逻辑挂钩的描述。
文件 细绳 包含逻辑挂钩类的文件路径。
班级 细绳 包含逻辑挂钩功能的类。
功能 细绳 逻辑挂钩将执行的函数。

The example below will demonstrate the $installdefs['logic_hooks'] index in the ./manifest.php. file, in order to add an after save logic hook to a specific module. You should note that when using this approach, you still need to use the $installdefs['copy'] index for the hook class file.

./manifest.php.

<?php

$manifest = array(
    ...
);

$installdefs = array(
    'id' => 'actionView_example',
    'logic_hooks' => array(
        array(
            'module' => '<module>',
            'hook' => 'after_save',
            'order' => 1,
            'description' => 'Example After Save LogicHook',
            'file' => 'custom/modules/<module>/module_hook.php',
            'class' => '<module>HookConsumer'
            'function' => 'after'
        )
    ),
    'copy' => array(
        array(
            'from' => '<basepath>/Files/custom/modules/<module>/module_hook.php',
            'to' => 'custom/modules/<module>/module_hook.php',
        ),
    )
);

最后修改:2020-03-16 17:00:15