From bb0a0e9f696fe8200b5e30d9b19c83992a971e89 Mon Sep 17 00:00:00 2001 From: "roman.lesnikov@gmail.com" Date: Thu, 30 Nov 2023 13:30:25 +0200 Subject: [PATCH] #4558 - Build-in API support (fix form fields visibility) --- template/scripts/BxBaseEmbedIframely.php | 2 +- template/scripts/BxBaseFormView.php | 52 ++++++++++++++---------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/template/scripts/BxBaseEmbedIframely.php b/template/scripts/BxBaseEmbedIframely.php index 759ff8fc35..e5704f001b 100644 --- a/template/scripts/BxBaseEmbedIframely.php +++ b/template/scripts/BxBaseEmbedIframely.php @@ -72,7 +72,7 @@ public function addJsCss () public function getDataFromApi ($sUrl, $sTheme) { - return bx_file_get_contents("https://iframe.ly/api/oembed?theme=" . $sTheme . "&url=" . $sUrl . "&api_key=" . getParam('sys_iframely_api_key')); + return bx_file_get_contents("https://iframe.ly/api/oembed?theme=" . $sTheme . "&url=" . $sUrl . "&api_key=" . getParam('sys_iframely_api_key') . "&card=small"); } public function getDataHtml ($sUrl, $sTheme) diff --git a/template/scripts/BxBaseFormView.php b/template/scripts/BxBaseFormView.php index d1414be1d2..4eea733e0c 100644 --- a/template/scripts/BxBaseFormView.php +++ b/template/scripts/BxBaseFormView.php @@ -355,32 +355,42 @@ function getCodeAPI() $this->genForm(); // TODO: process inputs to translate titles, alerts, etc + $keysToRemove = []; foreach ($this->aInputs as &$aInput) { - if (isset($aInput['type']) && 'files' == $aInput['type']){ - $oStorage = BxDolStorage::getObjectInstance($aInput['storage_object']); - $aInput['ext_allow'] = $oStorage->getObjectData()['ext_allow']; - $aInput['ext_deny'] = $oStorage->getObjectData()['ext_deny']; - $aInput['ghost_template'] = ''; - $aInput['value'] = ''; - $aInput['values'] = ''; - $aInput['values_src'] = ''; - } - - if (isset($aInput['type']) && 'location' == $aInput['type']){ - $aLocationIndexes = BxDolForm::$LOCATION_INDEXES; - $aVars = []; - $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default')); - foreach ($aLocationIndexes as $sKey) - $aVars[$sKey] = $o->getLocationVal($aInput, $sKey, $this); - if ($aVars['country']) { - $aCountries = BxDolFormQuery::getDataItems('Country'); - $sLocationString = ($aVars['street_number'] ? $aVars['street_number'] . ', ' : '') . ($aVars['street'] ? $aVars['street'] . ', ' : '') . ($aVars['city'] ? $aVars['city'] . ', ' : '') . ($aVars['state'] ? $aVars['state'] . ', ' : '') . $aCountries[$aVars['country']]; - $aVars['location_string'] = $sLocationString; + if (!isset($aInput['visible_for_levels']) || self::isVisible($aInput)) { + if (isset($aInput['type']) && 'files' == $aInput['type']){ + $oStorage = BxDolStorage::getObjectInstance($aInput['storage_object']); + $aInput['ext_allow'] = $oStorage->getObjectData()['ext_allow']; + $aInput['ext_deny'] = $oStorage->getObjectData()['ext_deny']; + $aInput['ghost_template'] = ''; + $aInput['value'] = ''; + $aInput['values'] = ''; + $aInput['values_src'] = ''; } - $aInput['value'] = $aVars; + + if (isset($aInput['type']) && 'location' == $aInput['type']){ + $aLocationIndexes = BxDolForm::$LOCATION_INDEXES; + $aVars = []; + $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default')); + foreach ($aLocationIndexes as $sKey) + $aVars[$sKey] = $o->getLocationVal($aInput, $sKey, $this); + if ($aVars['country']) { + $aCountries = BxDolFormQuery::getDataItems('Country'); + $sLocationString = ($aVars['street_number'] ? $aVars['street_number'] . ', ' : '') . ($aVars['street'] ? $aVars['street'] . ', ' : '') . ($aVars['city'] ? $aVars['city'] . ', ' : '') . ($aVars['state'] ? $aVars['state'] . ', ' : '') . $aCountries[$aVars['country']]; + $aVars['location_string'] = $sLocationString; + } + $aInput['value'] = $aVars; + } + } + else{ + $keysToRemove[] = $key; } } + + foreach ($keysToRemove as $key) { + unset($this->aInputs[$key]); + } return ['inputs' => $this->aInputs, 'attrs' => $this->aFormAttrs, 'params' => $this->aParams]; }