Skip to content

Commit

Permalink
New feature #18880: New imagefile option type for theme options (#3433)
Browse files Browse the repository at this point in the history
Co-authored-by: lapiudevgit <devgit@lapiu.biz>
  • Loading branch information
gabrieljenik and lapiudevgit committed Oct 5, 2023
1 parent 099c213 commit 251e460
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion application/models/TemplateConfiguration.php
Expand Up @@ -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,
],
Expand Down
65 changes: 62 additions & 3 deletions application/views/themeOptions/options_core.php
Expand Up @@ -7,7 +7,42 @@
"inherited value:"
) . ' ' . (isset($oParentOptions['font']) ? $oParentOptions['font'] : '') . ']</option>' : '');

/** @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 .= '</optgroup>';
}
$imageOptions .= '<optgroup label="' . $image['group'] . '">';
$optgroup = $image['group'];
}
$imageOptions .= '<option data-lightbox-src="' . $image['preview'] . '" value="' . $image['filepath'] . '">' . $image['filename'] . '</option>';
}

// 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 = '';
Expand All @@ -25,8 +60,8 @@

$backgroundImageFile .= '</optgroup>';
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 .= '<option data-lightbox-src="' . $image['preview'] . '" value="' . $image['filepath'] . '">' . $image['filename'] . '</option>';
}
Expand Down Expand Up @@ -184,6 +219,30 @@
echo $aOptionAttributes['optionAttributes'][$attributeKey]['dropdownoptions'];
echo '</select>
</div>';
} elseif ($attribute['type'] == 'imagefile') {
if (!is_string($sParentOption)) {
// TODO: $aParentOptions is not loaded properly, it seems.
$sParentOption = 'N/A';
}
echo '<div class="col-12">';
// Fields linked to a parent option (Yes/No switch) need a class and data-parent attribute
if (!empty($attribute['parent'])) {
echo '<select class="form-select selector_option_value_field selector_radio_childfield selector_image_selector" data-parent="' . $attribute['parent'] . '" data-inheritvalue=\'' . $sParentOption . '\' id="simple_edit_options_' . $attributeKey . '" name="' . $attributeKey . '" >';
} else {
echo '<select class="form-select selector_option_value_field selector_image_selector" data-inheritvalue=\'' . $sParentOption . '\' id="simple_edit_options_' . $attributeKey . '" name="' . $attributeKey . '" >';
}
if ($bInherit) {
if (isset($attribute['preview'])) {
$inheritedValue = $attribute['preview'];
} else {
$inheritedValue = isset($sParentOption) ? $sParentOption : '';
}
echo '<option value="inherit">' . gT("Inherit") . ' [' . gT("inherited value:") . ' ' . $inheritedValue . ']</option>';
}
// Dropdown options for image files
echo $imageOptions;
echo '</select>';
echo '</div>';
} elseif ($attribute['type'] == 'icon') {
echo ' <div class="col-12 input-group">
<select class="selector_option_value_field form-select simple_edit_options_checkicon" data-parent="' . $attribute['parent'] . '" id="simple_edit_options_' . $attributeKey . '" name="' . $attributeKey . '" >';
Expand All @@ -208,7 +267,7 @@

echo '</div>';

if ($category == 'Images' && $attribute['type'] == 'dropdown') {
if ($attribute['type'] == 'imagefile' || ($category == 'Images' && $attribute['type'] == 'dropdown')) {
echo '<div class="col-2">
<label class="form-label">&nbsp;</label>
<div class="col-12">
Expand Down

0 comments on commit 251e460

Please sign in to comment.