Module Builder & Logic Hooks?

I’m building a module, which I’ve done many times and am pretty familiar with how it works in module builder publishing/deploying, etc.

In this case though I have a pretty simple before save hook that I want to persist if I redeploy the module. (I’m hoping to build a complete package including the hook).

Can this be accomplished? I’v tried putting it here:

custom/Extension/modules/<YourCustomModule>/Ext/LogicHooks/

without any success.

I’ve seen a few posts here by searching, but don’t see any other answers other than “don’t redeploy”.

Anyone know if there is a way to do this?

Hi,

In the installdef array of your manifest, add a logic_hooks key, which should be an array of array like the following:

'logic_hooks' => array(
    array(
        'module' => <module_name>,
        'hook' => 'before_save',
        'order' => '',
        'description' => '',
        'file' => <class_path>,
        'class' => <class_name>,
        'function' => <function_name>
    )....

Once the package is installed, the declaration of your logic hook will be automatically added to the following file:
custom/modules/ModuleName/logic_hooks.php

2 Likes

Thanks I tried that but manifest.php gets over written on each save/redeploy. How can I avoid this, is there a way to extend it in module builder so it survives re-deploy?

I use a modified version of this utility made by a former SalesAgility dev

its philosophy is to build the manifest starting from a git diff, which is exactly what is useful for some ways of working, I don’t know if it fits yours…

Thanks @pgr what I did was put the logic class file in the module builder build directory. This gets pushed every time with deploy to the new module folder. The issue I was struggling with was the logic_hooks.php file. I couldn’t get it to push to /custom/modulename That’s where I was stuck. So what I eventually did was just add the call to the class in the main logic_hooks.php file in the root of /custom/ this never gets over written. Then I just reference my logic class file there. Now I can push from the module builder every time and not lose my hook.

It’s not perfect but it works for dev. I can later add the proper files to the zip and manifest.php for deployment (at least that’s my plan).

I’m working on something really cool!

I’ve built a software licensing system with Woocommerce and SuiteCRM. You sell the software on WP/Woocommerce, it pushes the order to a custom SuiteCRM licensing module that keeps track of the order, support length and creates a unique license key for each. I’ve got all that working. Next step is a SuiteCRM endpoint to allow updates based on the license key and the status being active.

2 Likes

The clean way to do this in SuiteCRM is to create a package and deploy it using the Module Installer. (Module Installer :: SuiteCRM Documentation)
If you want to update your module, you can make changes directly in the code, then uninstall and reinstall your package.
The problem with making changes directly in /custom/ is that if you run a repair, you’ll likely lose your hook.