protected function addHooksMethodCall(ContainerBuilder $container, Definition $definition)
    {
        $moduleHooks = ModuleHookQuery::create()
            ->orderByHookId()
            ->orderByPosition()
            ->orderById()
            ->find();

        $modulePosition = 0;
        $hookId = 0;
        /** @var ModuleHook $moduleHook */
        foreach ($moduleHooks as $moduleHook) {
            // check if class and method exists
            if (!$container->hasDefinition($moduleHook->getClassname())) {
                continue;
            }

            $hook = $moduleHook->getHook();

            if (!$this->isValidHookMethod(
                $container->getDefinition($moduleHook->getClassname())->getClass(),
                $moduleHook->getMethod(),
                $hook->getBlock(),
                true
            )
            ) {
                $moduleHook->delete();
                continue;
            }

            // manage module hook position for new hook
            if ($hookId !== $moduleHook->getHookId()) {
                $hookId = $moduleHook->getHookId();
                $modulePosition = 1;
            } else {
                $modulePosition++;
            }

            if ($moduleHook->getPosition() === ModuleHook::MAX_POSITION) {
                // new module hook, we set it at the end of the queue for this event
                $moduleHook->setPosition($modulePosition)->save();
            } else {
                $modulePosition = $moduleHook->getPosition();
            }

            // Add the the new listener for active hooks, we have to reverse the priority and the position
            if ($moduleHook->getActive() && $moduleHook->getModuleActive() && $moduleHook->getHookActive()) {
                $eventName = sprintf('hook.%s.%s', $hook->getType(), $hook->getCode());

                // we a register an event which is relative to a specific module
                if ($hook->getByModule()) {
                    $eventName .= '.' . $moduleHook->getModuleId();
                }

                $definition->addMethodCall(
                    'addListenerService',
                    array(
                        $eventName,
                        array($moduleHook->getClassname(), $moduleHook->getMethod()),
                        ModuleHook::MAX_POSITION - $moduleHook->getPosition()
                    )
                );

                if ($moduleHook->getTemplates()) {
                    if ($container->hasDefinition($moduleHook->getClassname())) {
                        $moduleHookEventName = 'hook.' . $hook->getType() . '.' . $hook->getCode();
                        if (true === $moduleHook->getHook()->getByModule()) {
                            $moduleHookEventName .= '.' . $moduleHook->getModuleId();
                        }
                        $container
                            ->getDefinition($moduleHook->getClassname())
                            ->addMethodCall(
                                'addTemplate',
                                array(
                                    $moduleHookEventName,
                                    $moduleHook->getTemplates()
                                )
                            )
                        ;
                    }
                }
            }
        }
    }