Hello everyone!
I have coded logic hooks for the Project module and everything was okay, but when I tried to replicate it for a custom module I haven’t managed to get it running. In fact I had to remove the logic hook files because it kept doing weird things, like not being able to add a relationship.
I tried to place the files in the /custom/modules/[Module] folder but I read in the documentation that it would be better to place the files in the Extension folder and then do a rebuild so that it generates another logic hook file, this time in /custom/modules/[Module] folder.
So I placed these files in the /custom/Extension/plata_Plataformas/Ext/LogicHooks/ folder:
logic_hooks.php
<?php
// Do not store anything in this file that is not part of the array or the hook version. This file will
// be automatically rebuilt in the future.
$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['after_relationship_add'] = Array();
$hook_array['after_relationship_add'][] = Array(1, 'addRelationship', 'custom/Extension/modules/plata_Plataformas/Ext/LogicHooks/logic_hook_after_relationships.php','logic_hook_after_relationships', 'fillRelationships');
$hook_array['after_relationship_delete'] = Array();
$hook_array['after_relationship_delete'][] = Array(2, 'deleteRelationship', 'custom/Extension/modules/plata_Plataformas/Ext/LogicHooks/logic_hook_after_relationships.php','logic_hook_after_relationships', 'fillRelationships');
?>
logic_hook_after_relationships.php
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class logic_hook_after_relationships
{
function fillRelationships(&$focus, $event, $arguments) {
$empresasAdheridas = $this->rellenaEntidad($focus->get_linked_beans('accounts','Accounts',array()));
$focus->empresas_c = $empresasAdheridas;
$focus->save(true);
}
function rellenaEntidad($arrayEmpresas) {
$str = "";
foreach ($arrayEmpresas as $bean) {
$str .= ", " . $bean->name;
}
$str = substr($str, 2);
return $str;
}
function rellenaAmbitos($arrayEmpresas) {
$str = "";
foreach ($arrayEmpresas as $bean) {
$str .= ", " . $bean->ambito;
}
$str = substr($str, 2);
return $str;
}
}
?>
And it generated this file in /custom/module/plata_Plataformas/Ext/LogicHooks/
logichooks.ext.php
<?php
//WARNING: The contents of this file are auto-generated
// Do not store anything in this file that is not part of the array or the hook version. This file will
// be automatically rebuilt in the future.
$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['after_relationship_add'] = Array();
$hook_array['after_relationship_add'][] = Array(1, 'addRelationship', 'custom/Extension/modules/plata_Plataformas/Ext/LogicHooks/logic_hook_after_relationships.php','logic_hook_after_relationships', 'fillRelationships');
$hook_array['after_relationship_delete'] = Array();
$hook_array['after_relationship_delete'][] = Array(2, 'deleteRelationship', 'custom/Extension/modules/plata_Plataformas/Ext/LogicHooks/logic_hook_after_relationships.php','logic_hook_after_relationships', 'fillRelationships');
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class logic_hook_after_relationships
{
function fillRelationships(&$focus, $event, $arguments) {
$empresasAdheridas = $this->rellenaEntidad($focus->get_linked_beans('accounts','Accounts',array()));
$focus->empresas_c = $empresasAdheridas;
$focus->save(true);
}
function rellenaEntidad($arrayEmpresas) {
$str = "";
foreach ($arrayEmpresas as $bean) {
$str .= ", " . $bean->name;
}
$str = substr($str, 2);
return $str;
}
function rellenaAmbitos($arrayEmpresas) {
$str = "";
foreach ($arrayEmpresas as $bean) {
$str .= ", " . $bean->ambito;
}
$str = substr($str, 2);
return $str;
}
}
?>
I think everything is okay, but if I add a relationship it doesn’t even show in the panel. And of course if I set a breakpoint in the function that gets called with the logic hook, it doesn’t stop, so the error is before the call… (How adding a logic hook can generate an error BEFORE the logic hook gets executed???)
This is the log error:
Any ideas?
Thanks!