/** * Generates the content of the hook * * {hook name="hook_code" var1="value1" var2="value2" ... } * * This function create an event, feed it with the custom variables passed to the function (var1, var2, ...) and * dispatch it to the hooks that respond to it. * * The name of the event is `hook.{context}.{hook_code}` where : * * context : the id of the context of the smarty render : 1: frontoffice, 2: backoffice, 3: email, 4: pdf * * hook_code : the code of the hook * * The event collects all the fragments of text rendered in each modules functions that listen to this event. * Finally, this fragments are concatenated and injected in the template * * @param array $params the params passed in the smarty function * @param \TheliaSmarty\Template\SmartyParser $smarty the smarty parser * * @return string the contents generated by modules */ public function processHookFunction($params, &$smarty) { $hookName = $this->getParam($params, 'name'); $module = intval($this->getParam($params, 'module', 0)); $moduleCode = $this->getParam($params, 'modulecode', ""); $type = $smarty->getTemplateDefinition()->getType(); $event = new HookRenderEvent($hookName, $params); $event->setArguments($this->getArgumentsFromParams($params)); $eventName = sprintf('hook.%s.%s', $type, $hookName); // this is a hook specific to a module if (0 === $module && "" !== $moduleCode) { if (null !== ($mod = ModuleQuery::create()->findOneByCode($moduleCode))) { $module = $mod->getId(); } } if (0 !== $module) { $eventName .= '.' . $module; } $this->getDispatcher()->dispatch($eventName, $event); $content = trim($event->dump()); if ($this->debug && $smarty->getRequest()->get('SHOW_HOOK')) { $content = sprintf('<div style="background-color: #C82D26; color: #fff; border-color: #000000; border: solid;">%s</div>%s', $hookName, $content); } $this->hookResults[$hookName] = $content; // support for compatibility with module_include if ($type === TemplateDefinition::BACK_OFFICE) { $content .= $this->moduleIncludeCompat($params, $smarty); } return $content; }