public function processHookBlock($params, $content, $smarty, &$repeat)
    {
        $hookName = $this->getParam($params, 'name');
        $module   = intval($this->getParam($params, 'module', 0));
        // explicit definition of variable that can be returned
        $fields   = preg_replace(
            '|[^a-zA-Z0-9,\-_]|',
            '',
            $this->getParam($params, 'fields', '')
        );
        $fields = ('' !== $fields) ? explode(",", $fields) : [];

        if (!$repeat) {
            if ($this->debug && $smarty->getRequest()->get('SHOW_HOOK')) {
                $content = self::showHook($hookName, $params) . $content;
            }

            return $content;
        }

        $type = $smarty->getTemplateDefinition()->getType();

        $event = new HookRenderBlockEvent($hookName, $params, $fields, $smarty->getTemplateVars());

        $event->setArguments($this->getArgumentsFromParams($params));

        $eventName = sprintf('hook.%s.%s', $type, $hookName);

        // this is a hook specific to a module
        if (0 !== $module) {
            $eventName .= '.' . $module;
        }

        $this->getDispatcher()->dispatch($eventName, $event);

        // save results so we can use it in forHook block
        $this->hookResults[$hookName] = $event->get();
    }
public function processHookBlock($params, $content, $smarty, &$repeat)
    {
        $hookName = $this->getParam($params, 'name');
        $module   = intval($this->getParam($params, 'module', 0));
        // explicit definition of variable that can be returned
        $fields   = preg_replace(
            '|[^a-zA-Z0-9,\-_]|',
            '',
            $this->getParam($params, 'fields', '')
        );
        $fields = ('' !== $fields) ? explode(",", $fields) : [];

        if (!$repeat) {
            if ($this->debug && $smarty->getRequest()->get('SHOW_HOOK')) {
                $content = self::showHook($hookName, $params) . $content;
            }

            return $content;
        }

        $type = $smarty->getTemplateDefinition()->getType();

        $event = new HookRenderBlockEvent($hookName, $params, $fields, $smarty->getTemplateVars());

        $event->setArguments($this->getArgumentsFromParams($params));

        $eventName = sprintf('hook.%s.%s', $type, $hookName);

        // this is a hook specific to a module
        if (0 !== $module) {
            $eventName .= '.' . $module;
        }

        $this->getDispatcher()->dispatch($eventName, $event);

        // save results so we can use it in forHook block
        $this->hookResults[$hookName] = $event->get();
    }
public function processHookBlock ( $ params , $ content , $ smarty , & $ repeat ) { $ hookName = $ this -> getParam ( $ params , 'name' ) ; $ module = intval ( $ this -> getParam ( $ params , 'module' , 0 ) ) ; // explicit definition of variable that can be returned $ fields = preg_replace ( '|[^a-zA-Z0-9,\-_]|' , '' , $ this -> getParam ( $ params , 'fields' , '' ) ) ; $ fields = ( '' !== $ fields ) ? explode ( "," , $ fields ) : [ ] ; if ( ! $ repeat ) { if ( $ this -> debug && $ smarty -> getRequest ( ) -> get ( 'SHOW_HOOK' ) ) { $ content = self :: showHook ( $ hookName , $ params ) . $ content ; } return $ content ; } $ type = $ smarty -> getTemplateDefinition ( ) -> getType ( ) ; $ event = new HookRenderBlockEvent ( $ hookName , $ params , $ fields , $ smarty -> getTemplateVars ( ) ) ; $ event -> setArguments ( $ this -> getArgumentsFromParams ( $ params ) ) ; $ eventName = sprintf ( 'hook.%s.%s' , $ type , $ hookName ) ; // this is a hook specific to a module if ( 0 !== $ module ) { $ eventName .= '.' . $ module ; } $ this -> getDispatcher ( ) -> dispatch ( $ eventName , $ event ) ; // save results so we can use it in forHook block $ this -> hookResults [ $ hookName ] = $ event -> get ( ) ; }
Process the content of the hook block.

{hookblock 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 generated by modules that listen to this event and add it to a fragmentBag.
This fragmentBag is not used directly. This is the forhook block that iterates over the fragmentBag to inject
data in the template.

@param array        $params
@param string       $content
@param \TheliaSmarty\Template\SmartyParser $smarty
@param bool         $repeat

@return string the generated content
Process the content of the hook block .