I see this example code that contains a method called StampIt that has 2 arguments $focus and $event
//prevents directly accessing this file from a web browser
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
function StampIt(& $focus, $event)
$focus->description .= "Saved on ". date("Y-m-d g:i a"). " by ". $current_user->user_name; }
I’m just trying to understand where $event argument is used since it’s not mentioned anywhere inside the StampIt method
Logic hook functions follow a pre-set format, with regular parameters (event, bean, focus) depending on the kind of hook it is. You don’t have to use the parameters, often you don’t, but they have to be there to match the pre-set format.
By the way, when I’m trying to understand code I save a lot of time by looking at the values of variables, stepping through code with a debugger, or just dumping variables into the logs, instead of asking in Forums
appreciate the tips! in this case I got another reply from stackoverflow and they indicated that this value is simply not used at all inside the method, so that’s what was confusing me.
$event will contain the name of the currently executing event/hook type during runtime. This is useful if a single method is hooked into more than one event and needs to alter its logic based on what event triggered it.
In this particular example we know that $event will always contain the string before_safe as this is the only event our example method has been hooked into. No other event will ever call that method.
That is why the variable remains unused in this example, as the method does not have to handle more than that single event type anyway and would also not gain any new information by reading $event.