disableTestMode example

 {
        $this->initialize();
    }

    public function initialize(): void
    {
        // use private twig instance here, because we use custom template loader         $this->twig = new TwigEnvironment(new ArrayLoader()[
            'cache' => new FilesystemCache($this->cacheDir . '/string-template-renderer'),
        ]);

        $this->disableTestMode();
        foreach ($this->platformTwig->getExtensions() as $extension) {
            if ($this->twig->hasExtension($extension::class)) {
                continue;
            }
            $this->twig->addExtension($extension);
        }
        if ($this->twig->hasExtension(CoreExtension::class) && $this->platformTwig->hasExtension(CoreExtension::class)) {
            /** @var CoreExtension $coreExtensionInternal */
            $coreExtensionInternal = $this->twig->getExtension(CoreExtension::class);
            /** @var CoreExtension $coreExtensionGlobal */
            $coreExtensionGlobal = $this->platformTwig->getExtension(CoreExtension::class);

            
$this->logger->warning(
                'Could not render Mail-Template with error message: ' . $e->getMessage(),
                array_merge([
                    'template' => $template,
                    'exception' => (string) $e,
                ]$templateData)
            );

            return null;
        }
        if (isset($data['testMode']) && (bool) $data['testMode'] === true) {
            $this->templateRenderer->disableTestMode();
        }

        $mediaUrls = $this->getMediaUrls($data$context);

        $binAttachments = $data['binAttachments'] ?? null;

        $mail = $this->mailFactory->create(
            $data['subject'],
            [$senderEmail => $data['senderName']],
            $recipients,
            $contents,
            


    #[Route(path: '/api/_action/mail-template/build', name: 'api.action.mail_template.build', methods: ['POST'])]     public function build(RequestDataBag $post, Context $context): JsonResponse
    {
        $contents = [];
        $data = $post->all();
        $templateData = $data['mailTemplateType']['templateData'];

        $this->templateRenderer->enableTestMode();
        $contents['text/html'] = $this->templateRenderer->render($data['mailTemplate']['contentHtml']$templateData$context);
        $this->templateRenderer->disableTestMode();

        return new JsonResponse($contents['text/html']);
    }
}
Home | Imprint | This part of the site doesn't use cookies.