Source of file GalleryExtension.php
Size: 2,014 Bytes - Last Modified: 2021-12-23T10:58:10+00:00
/var/www/docs.ssmods.com/process/src/code/GalleryExtension.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 | <?php /** * @property SiteTree $owner */ class GalleryExtension extends SiteTreeExtension { private static $has_many = [ 'PrimaryGalleryImages' => 'PrimaryGalleryImage', 'SecondaryGalleryImages' => 'SecondaryGalleryImage', ]; public function updateCMSFields(FieldList $fields) { foreach (['primary', 'secondary'] as $lower) { $upper = ucfirst($lower); $fields->removeByName("{$upper}GalleryImages"); $config = $this->owner->config()->get("{$lower}_gallery"); if (is_null($config) || (isset($config['enabled']) && $config['enabled'] === false)) { continue; } $config['title'] = isset($config['title']) ? $config['title'] : "{$upper} Gallery"; $config['folder'] = isset($config['folder']) ? $config['folder'] : "{$upper}-Gallery-Images"; $GridFieldConfig = new GridFieldConfig_RecordEditor(); $GridFieldConfig->removeComponentsByType('GridFieldAddNewButton'); $GridFieldConfig->addComponent($bulkUploadConfig = new GridFieldBulkUpload()); $GridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder')); $GridFieldConfig->addComponent(new GridFieldGalleryTheme('Image')); $bulkUploadConfig->setUfSetup('setFolderName', "Images/{$config['folder']}"); $GridField = new GridField("{$upper}GalleryGridField", $config['title'], $this->owner->{"{$upper}GalleryImages"}(), $GridFieldConfig); /** @var TabSet $rootTab */ //We need to repush Metadata to ensure it is the last tab $rootTab = $fields->fieldByName('Root'); if ($this->owner->exists()) { $rootTab->push($tab = Tab::create("{$upper}Gallery")); } if ($this->owner->exists()) { $fields->addFieldToTab("Root.{$upper}Gallery", $GridField); $tab->setTitle($config['title']); } } } } |