Skip to content

Commit

Permalink
#4558 - Build-in API support (fix form fields visibility)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlesnikov committed Nov 30, 2023
1 parent 82eae22 commit bb0a0e9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion template/scripts/BxBaseEmbedIframely.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
52 changes: 31 additions & 21 deletions template/scripts/BxBaseFormView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down

0 comments on commit bb0a0e9

Please sign in to comment.