Skip to content

Commit

Permalink
Update ElementContentExtension.php
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz-sauer-13 authored Dec 19, 2023
1 parent 17ce0cc commit 0ca46d5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Extensions/ElementContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;
use UncleCheese\Forms\ImageOptionsetField;

class ElementContentExtension extends DataExtension{

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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 : '',
];
}
}
Expand Down

0 comments on commit 0ca46d5

Please sign in to comment.