Browse Source

#4558 - Build-in API support (fix form fields visibility)

roman.lesnikov@gmail.com 2 years ago
parent
commit
bb0a0e9f69
2 changed files with 32 additions and 22 deletions
  1. 1 1
      template/scripts/BxBaseEmbedIframely.php
  2. 31 21
      template/scripts/BxBaseFormView.php

+ 1 - 1
template/scripts/BxBaseEmbedIframely.php

@@ -72,7 +72,7 @@ class BxBaseEmbedIframely extends BxDolEmbed
     
     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)

+ 31 - 21
template/scripts/BxBaseFormView.php

@@ -355,32 +355,42 @@ class BxBaseFormView extends BxDolForm
             $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];
     }