public function getCMSFields() { $fields = new FieldList(new TabSet('Root')); // Details $thumbnailField = new UploadField('CoverImage', _t('ImageGalleryAlbum.COVERIMAGE', 'Cover Image')); $thumbnailField->getValidator()->setAllowedExtensions(File::config()->app_categories['image']); $fields->addFieldsToTab('Root.Main', array(new TextField('AlbumName', _t('ImageGalleryAlbum.ALBUMTITLE', 'Album Title'), null, 255), new TextareaField('Description', _t('ImageGalleryAlbum.DESCRIPTION', 'Description')), $thumbnailField)); // Image listing $galleryConfig = GridFieldConfig_RecordEditor::create(); // Enable bulk image loading if necessary module is installed // @see composer.json/suggests if (class_exists('GridFieldBulkManager')) { $galleryConfig->addComponent(new GridFieldBulkManager()); } if (class_exists('GridFieldBulkImageUpload')) { $galleryConfig->addComponents($imageConfig = new GridFieldBulkImageUpload('ImageID')); $imageConfig->setConfig('fieldsClassBlacklist', array('ImageField', 'UploadField', 'FileField')); if ($uploadFolder = $this->Folder()) { // Set upload folder - Clean up 'assets' from target path $path = preg_replace('/(^' . ASSETS_DIR . '\\/?)|(\\/$)/i', '', $uploadFolder->RelativePath); $imageConfig->setConfig('folderName', $path); } } // Enable image sorting if necessary module is installed // @see composer.json/suggests if (class_exists('GridFieldSortableRows')) { $galleryConfig->addComponent(new GridFieldSortableRows('SortOrder')); } $galleryField = new GridField('GalleryItems', 'Gallery Items', $this->GalleryItems(), $galleryConfig); $fields->addFieldToTab('Root.Images', $galleryField); return $fields; }
public function updateCMSFields(FieldList $fields) { parent::updateCMSFields($fields); $fields->removeByName('Images'); $name = Config::inst()->get('SimpleGalleryExtension', 'gallery_name'); if ($this->owner->ID > 0) { $folder = Config::inst()->get('SimpleGalleryExtension', 'folder_path'); if (strlen($folder) == 0) { $folder = 'simplegallery'; } $gridFieldConfig = GridFieldConfig_RecordEditor::create(); $bu = new GridFieldBulkImageUpload('Image', array('Title')); $bu->setConfig('folderName', $folder); $gridFieldConfig->addComponent($bu); $gridFieldSortableRows = new GridFieldSortableRows('SortOrder'); $gridFieldConfig->addComponent($gridFieldSortableRows->setAppendToTop(true)); $gridfield = new GridField("Gallery", $name, $this->SortedImages(true), $gridFieldConfig); $fields->addFieldToTab('Root.' . $name, $gridfield); } return $fields; }