From 251e46095fc01a47b16fb740dde99fec4dceab5c Mon Sep 17 00:00:00 2001 From: Gabriel Jenik Date: Thu, 5 Oct 2023 11:54:53 -0300 Subject: [PATCH] New feature #18880: New imagefile option type for theme options (#3433) Co-authored-by: lapiudevgit --- application/models/TemplateConfiguration.php | 2 +- .../views/themeOptions/options_core.php | 65 ++++++++++++++++++- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/application/models/TemplateConfiguration.php b/application/models/TemplateConfiguration.php index 38f86dac195..e952995d64a 100755 --- a/application/models/TemplateConfiguration.php +++ b/application/models/TemplateConfiguration.php @@ -1014,7 +1014,7 @@ public function getOptionPageAttributes() foreach ($fileList as $file) { $imageInfo = $this->getImageInfo($basePath . $file['name'], $pathPrefix); if ($imageInfo) { - $aData['imageFileList'][] = array_merge( + $aData['imageFileList'][$imageInfo['filepath']] = array_merge( [ 'group' => $category->title, ], diff --git a/application/views/themeOptions/options_core.php b/application/views/themeOptions/options_core.php index fa44841c6e2..64add5fa6ca 100644 --- a/application/views/themeOptions/options_core.php +++ b/application/views/themeOptions/options_core.php @@ -7,7 +7,42 @@ "inherited value:" ) . ' ' . (isset($oParentOptions['font']) ? $oParentOptions['font'] : '') . ']' : ''); +/** @var string The html for image file dropdown options */ +$imageOptions = ''; +$optgroup = ''; +foreach ($aTemplateConfiguration['imageFileList'] as $image) { + // If group is different than the previous one, close the previous optgroup and open a new one + if ($image['group'] != $optgroup) { + if ($optgroup != '') { + $imageOptions .= ''; + } + $imageOptions .= ''; + $optgroup = $image['group']; + } + $imageOptions .= ''; +} +// Add extra info needed for theme options of type "imagefile" (preview path and filename) +foreach ($aOptionAttributes['optionAttributes'] as $attributeName => &$attribute) { + if ($attribute['type'] == 'imagefile') { + if (!isset($oParentOptions[$attributeName])) { + continue; + } + if (isset($aTemplateConfiguration['imageFileList'][$oParentOptions[$attributeName]])) { + $image = $aTemplateConfiguration['imageFileList'][$oParentOptions[$attributeName]]; + $attribute['preview'] = $image['preview']; + $attribute['filename'] = $image['filename']; + } else { + $attribute['preview'] = ''; + $attribute['filename'] = ''; + } + } +} +unset($attribute); + +/** + * @todo: Convert backgroundimagefile and brandlogofile to 'imagefile' type + */ // background file $backgroundImageFile = ''; $backgroundfileOptionsInherit = ''; @@ -25,8 +60,8 @@ $backgroundImageFile .= ''; if (isset($oParentOptions['backgroundimagefile']) && $oParentOptions['backgroundimagefile'] == $image['filepath']) { - $backgroundfileInheritPreview = $backgroundimagefileInheritPreview . $image['preview']; - $backgroundfileInheritFilename = $backgroundimagefileInheritFilename . $image['filename']; + $backgroundfileInheritPreview = $backgroundfileInheritPreview . $image['preview']; + $backgroundfileInheritFilename = $backgroundfileInheritFilename . $image['filename']; } $backgroundImageFile .= ''; } @@ -184,6 +219,30 @@ echo $aOptionAttributes['optionAttributes'][$attributeKey]['dropdownoptions']; echo ' '; + } elseif ($attribute['type'] == 'imagefile') { + if (!is_string($sParentOption)) { + // TODO: $aParentOptions is not loaded properly, it seems. + $sParentOption = 'N/A'; + } + echo '
'; + // Fields linked to a parent option (Yes/No switch) need a class and data-parent attribute + if (!empty($attribute['parent'])) { + echo ''; + } + if ($bInherit) { + if (isset($attribute['preview'])) { + $inheritedValue = $attribute['preview']; + } else { + $inheritedValue = isset($sParentOption) ? $sParentOption : ''; + } + echo ''; + } + // Dropdown options for image files + echo $imageOptions; + echo ''; + echo '
'; } elseif ($attribute['type'] == 'icon') { echo '