Skip to content

Commit

Permalink
inital Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mosau authored and mosau committed Mar 27, 2022
1 parent 9d68a99 commit f2c2bec
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 0 deletions.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file added _config.php
Empty file.
3 changes: 3 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
Name: HeroElement
---
Empty file modified composer.json
100644 → 100755
Empty file.
37 changes: 37 additions & 0 deletions src/DataObjects/Slide.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\Image;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataObject;

class Slide extends DataObject{
private static $db = [
'SortOrder' => '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;
}
}
59 changes: 59 additions & 0 deletions src/Elements/HeroElement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

use DNADesign\Elemental\Models\BaseElement;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;

class HeroElement extends BaseElement{
private static $db = [
'Title' => '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()');
}
}
8 changes: 8 additions & 0 deletions src/lang/de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
de:
General:
TITLE: 'Titel'
Slide:
IMAGE: 'Bild'
Element:
HEROELEMENT: 'Hero Element'
SLIDES: 'Folien'

0 comments on commit f2c2bec

Please sign in to comment.