data = $data; if (class_exists(LayoutSettings::class)) { $this->layoutSettings = ObjectManager::getInstance()->create(LayoutSettings::class); $this->config = ObjectManager::getInstance()->create(Config::class); } $this->json = ObjectManager::getInstance()->get( Json::class); } /** * @inheritdoc */ public function getJsLayout() { $layout = $this->json->unserialize(parent::getJsLayout()); if ($this->config && $this->config->isEnabledFrontend()) { // Backward compatibility with fixed scope name if (isset($layout['components']['msp-recaptcha'])) { $layout['components'][$this->getRecaptchaId()] = $layout['components']['msp-recaptcha']; unset($layout['components']['msp-recaptcha']); } $recaptchaComponentSettings = []; if (isset($layout['components'][$this->getRecaptchaId()]['settings'])) { $recaptchaComponentSettings = $layout['components'][$this->getRecaptchaId()]['settings']; } $layout['components'][$this->getRecaptchaId()]['settings'] = array_replace_recursive( $this->layoutSettings->getCaptchaSettings(), $recaptchaComponentSettings ); $layout['components'][$this->getRecaptchaId()]['reCaptchaId'] = $this->getRecaptchaId(); } return $this->json->serialize($layout); } /** * Get current recaptcha ID */ public function getRecaptchaId() { return (string)$this->getData('recaptcha_id') ?: 'msp-recaptcha-' . md5($this->getNameInLayout()); } /** * @return string */ public function toHtml() { if (!$this->config || !$this->config->isEnabledFrontend()) { return ''; } return parent::toHtml(); } }