From f2c2bec8cc8cc615df3de6967b891f782a972b29 Mon Sep 17 00:00:00 2001 From: mosau Date: Sun, 27 Mar 2022 16:32:28 +0200 Subject: [PATCH] inital Commit --- README.md | 0 _config.php | 0 _config/config.yml | 3 ++ composer.json | 0 src/DataObjects/Slide.php | 37 ++++++++++++++++++++++ src/Elements/HeroElement.php | 59 ++++++++++++++++++++++++++++++++++++ src/lang/de.yml | 8 +++++ 7 files changed, 107 insertions(+) mode change 100644 => 100755 README.md create mode 100644 _config.php create mode 100644 _config/config.yml mode change 100644 => 100755 composer.json create mode 100644 src/DataObjects/Slide.php create mode 100644 src/Elements/HeroElement.php create mode 100644 src/lang/de.yml diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/_config.php b/_config.php new file mode 100644 index 0000000..e69de29 diff --git a/_config/config.yml b/_config/config.yml new file mode 100644 index 0000000..d9e151d --- /dev/null +++ b/_config/config.yml @@ -0,0 +1,3 @@ +--- +Name: HeroElement +--- diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 diff --git a/src/DataObjects/Slide.php b/src/DataObjects/Slide.php new file mode 100644 index 0000000..771e927 --- /dev/null +++ b/src/DataObjects/Slide.php @@ -0,0 +1,37 @@ + 'Int', + 'Title' => 'Text', + ]; + + private static $has_one = [ + 'HeroElement' => HeroElement::class, + 'Image' => Image::class + ]; + + public function getCMSFields(): \SilverStripe\Forms\FieldList + { + $fields = parent::getCMSFields(); + + $fields->removeByName([ + 'SortOrder', + 'HeroElementID' + ]); + + $fields->addFieldsToTab('Root.Main', [ + TextField::create('Title', _t('General.TITLE', 'Title')), + UploadField::create('Image', _t('Slide.IMAGE', 'Image')), + ]); + + $this->extend('updateSlideCMSFields', $fields); + + return $fields; + } +} \ No newline at end of file diff --git a/src/Elements/HeroElement.php b/src/Elements/HeroElement.php new file mode 100644 index 0000000..8206736 --- /dev/null +++ b/src/Elements/HeroElement.php @@ -0,0 +1,59 @@ + 'Text', + ]; + + private static $has_many = [ + 'Slides' => Slide::class + ]; + + public function getCMSFields(): \SilverStripe\Forms\FieldList + { + $fields = parent::getCMSFields(); + + $fields->removeByName([ + 'Slides', + ]); + + $fields->addFieldsToTab('Root.Main', [ + GridField::create( + 'Slides', + _t('Element.SLIDES', 'Slides'), + $this->Slides()->sort('SortOrder ASC'), + GridFieldConfig_RecordEditor::create() + ->addComponent(GridFieldOrderableRows::create('SortOrder')) + ), + ]); + + return $fields; + } + + public function inlineEditable(): bool + { + return false; + } + + public function getType(): string + { + return _t('Element.HEROELEMENT', 'Hero Element'); + } + + public function getASCSortedSlides(){ + return $this->Slides()->sort('SortOrder ASC'); + } + + public function getDESCSortedSlides(){ + return $this->Slides()->sort('SortOrder DESC'); + } + + public function getRANDOMSortedSlides(){ + return $this->Slides()->sort('RAND()'); + } +} \ No newline at end of file diff --git a/src/lang/de.yml b/src/lang/de.yml new file mode 100644 index 0000000..31d7475 --- /dev/null +++ b/src/lang/de.yml @@ -0,0 +1,8 @@ +de: + General: + TITLE: 'Titel' + Slide: + IMAGE: 'Bild' + Element: + HEROELEMENT: 'Hero Element' + SLIDES: 'Folien' \ No newline at end of file