Source of file HeaderPicExtension.php
Size: 2,209 Bytes - Last Modified: 2021-12-23T10:59:31+00:00
/var/www/docs.ssmods.com/process/src/src/extensions/HeaderPicExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 | <?php namespace Netwerkstatt\HeaderGallery\Extensions; use Colymba\BulkUpload\BulkUploader; use Netwerkstatt\HeaderGallery\Model\HeaderPicResource; use Page; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; use SilverStripe\ORM\DataExtension; use SilverStripe\ORM\ManyManyList; class HeaderPicExtension extends DataExtension { private static $many_many = [ 'HeaderGallery' => HeaderPicResource::class ]; private static $many_many_extraFields = [ 'HeaderGallery' => [ 'SortOrder' => 'Int' ] ]; private static $delete_permission = 'CMS_ACCESS_CMSMain'; public function updateCMSFields(FieldList $fields) { $conf = GridFieldConfig_RelationEditor::create(10); // $conf->addComponent(new GridFieldSortableRows('SortOrder')); //@todo: update when module is SS4 ready // $conf->addComponent(new GridFieldGalleryTheme('Attachment'));//@todo: update when module is SS4 readygit $conf->addComponent(new BulkUploader()); $conf->getComponentByType(BulkUploader::class)->setUfSetup('setFolderName', 'header'); $fields->addFieldToTab( 'Root.HeaderGalerie', Gridfield::create('HeaderGallery', 'Slideshow für Header', $this->owner->HeaderGallery(), $conf) ); } /** * Method to get the HeaderGallery with fallback to parent pages or HomePage * * @return ManyManyList|null */ public function getHeaderGalleryPics() { $owner = $this->owner; if (!$owner) { return; } if (isset($owner->ID) && $owner->HeaderGallery()->count() > 0) { return $owner->HeaderGallery(); } $Parent = isset($owner->ID) ? $owner->Parent() : $Parent = $this->owner->Parent(); if (is_object($Parent) && $Parent->ID != 0) { return $Parent->getHeaderGalleryPics(); } //return Gallery of Home Page $home = Page::get()->filter(['URLSegment' => 'home'])->first(); return $home ? $home->HeaderGallery() : null; } } |