From 0ca46d5707a3bbd9b5e896e9f603e05767a232e8 Mon Sep 17 00:00:00 2001 From: Moritz Sauer <43135946+moritz-sauer-13@users.noreply.github.com> Date: Tue, 19 Dec 2023 13:46:26 +0100 Subject: [PATCH] Update ElementContentExtension.php --- src/Extensions/ElementContentExtension.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Extensions/ElementContentExtension.php b/src/Extensions/ElementContentExtension.php index 486ab5d..1306130 100644 --- a/src/Extensions/ElementContentExtension.php +++ b/src/Extensions/ElementContentExtension.php @@ -19,6 +19,7 @@ use SilverStripe\Forms\TreeDropdownField; use SilverStripe\ORM\DataExtension; use SilverStripe\ORM\DataObject; +use UncleCheese\Forms\ImageOptionsetField; class ElementContentExtension extends DataExtension{ @@ -81,7 +82,10 @@ public function updateCMSFields(FieldList $fields): FieldList ]); /*Layout field*/ - DropdownField::create('ElementStyle', 'Layout wählen')->setSource($this->getLayoutOptions()); + $layoutField = ImageOptionsetField::create('ElementStyle', 'Layout wählen')->setSource($this->getLayoutOptions()); + $layoutField->setImageHeight($this->getConfigVariable('FieldSettings', 'ImageHeight')); + $layoutField->setImageWidth($this->getConfigVariable('FieldSettings', 'ImageWidth')); + $layoutField->setDescription($this->getConfigVariable('FieldSettings', 'FieldDescription')); $fields->addFieldToTab('Root.Main', $layoutField, 'MenuTitle'); @@ -184,9 +188,17 @@ private function getLayoutOptions(): array foreach ($configVars as $layoutVar){ $layoutID = $layoutVar['id']; if($this->getLayoutVariableFromConfig($layoutID)){ + if(stristr($layoutVar['imgPath'], 'themes/') !== false){ + $img = $layoutVar['imgPath']; + } else { + $img = ModuleLoader::getModule('moritz-sauer-13/contentelement')->getResource($layoutVar['imgPath']); + if($img){ + $img->getURL(); + } + } $options[$layoutID] = [ - 'ID' => $layoutVar['id'], - 'image' => $layoutVar['title'], + 'title' => $layoutVar['title'], + 'image' => ($img) ? Director::absoluteBaseURL() . 'resources/' . $img : '', ]; } }