styleUtils = $styleUtils; $this->settings = $settings; $this->blocksRenderer = $blocksRenderer; $this->customFonts = $customFonts; } public function renderStyles(FormEntity $form, string $prefix, string $displayType): string { $this->customFonts->enqueueStyle(); $html = $this->styleUtils->prefixStyles($this->getCustomStyles($form), $prefix); $html .= strip_tags($this->styleUtils->renderFormSettingsStyles($form, $prefix, $displayType)); return $html; } public function renderHTML(FormEntity $form = null): string { if (($form instanceof FormEntity) && !empty($form->getBody()) && is_array($form->getSettings())) { return $this->renderBlocks($form->getBody(), $form->getSettings() ?? [], $form->getId()); } return ''; } public function getCustomStyles(FormEntity $form = null): string { if (($form instanceof FormEntity) && (strlen(trim($form->getStyles() ?? '')) > 0)) { return strip_tags($form->getStyles() ?? ''); } else { return FormTemplate::DEFAULT_STYLES; } } public function renderBlocks( array $blocks = [], array $formSettings = [], ?int $formId = null, bool $honeypotEnabled = true, bool $captchaEnabled = true ): string { // add honeypot for spambots $html = ($honeypotEnabled) ? $this->renderHoneypot() : ''; foreach ($blocks as $key => $block) { if ( $captchaEnabled && $block['type'] === FormEntity::SUBMIT_BLOCK_TYPE && CaptchaConstants::isRecaptcha($this->settings->get('captcha.type')) ) { $html .= $this->renderReCaptcha(); } if (in_array($block['type'], [FormEntity::COLUMN_BLOCK_TYPE, FormEntity::COLUMNS_BLOCK_TYPE])) { $blocks = $block['body'] ?? []; $html .= $this->blocksRenderer->renderContainerBlock($block, $this->renderBlocks($blocks, $formSettings, $formId, false)) . PHP_EOL; } else { $html .= $this->blocksRenderer->renderBlock($block, $formSettings, $formId) . PHP_EOL; } } return $html; } private function renderHoneypot(): string { return ''; } private function renderReCaptcha(): string { if ($this->settings->get('captcha.type') === CaptchaConstants::TYPE_RECAPTCHA) { $siteKey = $this->settings->get('captcha.recaptcha_site_token'); $size = ''; } else { $siteKey = $this->settings->get('captcha.recaptcha_invisible_site_token'); $size = 'invisible'; } $html = '