public function updateCMSFields(FieldList $fields) { $sortable = singleton('CleanTeaser')->hasExtension('SortableDataExtension'); $config = GridFieldConfig_RelationEditor::create(); $config->addComponent($gridFieldForm = new GridFieldDetailForm()); $dataFields = array(); if (singleton('CleanTeaser')->hasExtension('CMSPublishableDataExtension')) { $dataFields['PublishIndicator'] = 'Published'; } $dataFields = array_merge($dataFields, array('Thumbnail' => 'Thumbnail', 'Title' => 'Title', 'CleanDescription' => 'Description')); $config->getComponentByType('GridFieldDataColumns')->setDisplayFields($dataFields); $gridFieldForm->setTemplate('CMSGridFieldPopupForms'); if ($sortable) { $config->addComponent(new GridFieldSortableRows('SortOrder')); } if (ClassInfo::exists('GridFieldBulkUpload')) { $iu = new GridFieldBulkUpload('ImageID'); if (singleton('CleanTeaser')->hasExtension('ControlledFolderDataExtension')) { $iu->setUfConfig('folderName', singleton('CleanTeaser')->getUploadFolder()); } else { $iu->setUfConfig('folderName', CleanTeaser::$upload_folder); } $config->addComponent($iu); } if ($sortable) { $data = $this->owner->CleanTeasers("ClassName = 'CleanTeaser'")->sort('SortOrder'); } else { $data = $this->owner->CleanTeasers("ClassName = 'CleanTeaser'"); } // $config->removeComponentsByType('GridFieldAddNewButton'); // if (ClassInfo::exists('GridFieldBulkUpload')) { // $config->addComponent(new GridFieldAddNewMultiClass()); // } $fields->addFieldToTab("Root.Teasers", GridField::create('CleanTeasers', 'CleanTeaser', $data, $config)); }
public function getCMSFields() { $fields = parent::getCMSFields(); // Main Content tab // Carousel tab $carouselItemsGrid = null; // Manay to many relations can only be established if we have an id. So put a place holder instead of a grid if this is a new object. if ($this->ID == 0) { $carouselItemsGrid = TextField::create("CarouselItems", "Carousel Items")->setDisabled(true)->setValue("Page must be saved once before adding Carousel Items."); } else { $carouselItemsGrid = new GridField('CarouselItems', 'Carousel', $this->CarouselItems()->sort('Archived'), GridFieldConfig_RelationEditor::create()); $carouselItemsGridUploadComponent = new GridFieldBulkUpload("Image"); $carouselItemsGridUploadComponent->setUfSetup("setFolderName", $this->ImageFolder("carousel")); $carouselItemsGrid->setModelClass('CarouselItem')->getConfig()->addComponent($carouselItemsGridUploadComponent)->addComponent(new GridFieldOrderableRows("SortID")); } $fields->addFieldToTab('Root.Carousel', $carouselItemsGrid); // Links $fields->addFieldToTab('Root.Links', new TreeDropdownField('LearnMorePageID', 'Page to link the "Learn More" button to:', 'SiteTree')); $fields->addFieldToTab('Root.Links', new TextField('LearnMoreButtonText', 'Text to display on the "Learn More" button:', 'SiteTree')); $quickLinksGrid = new GridField('Quicklinks', 'Quicklinks', $this->Quicklinks(), GridFieldConfig_RelationEditor::create()); $quickLinksGrid->setModelClass('Quicklink'); $quickLinksFieldGroup = FieldGroup::create($quickLinksGrid)->setTitle('Quick Links'); $quickLinksFieldGroup->setName("QuicklinkGroup"); $fields->addFieldToTab('Root.Links', $quickLinksFieldGroup); $fields->removeByName('Translations'); $fields->removeByName('Import'); $fields->addFieldToTab('Root.Features', ToggleCompositeField::create('FeatureOne', _t('SiteTree.FeatureOne', 'Feature One'), array(new TextField('FeatureOneTitle', 'Title'), new DropdownField('FeatureOneCategory', 'Category', singleton('ExpressHomePage')->dbObject('FeatureOneCategory')->enumValues()), new HTMLEditorField('FeatureOneContent', 'Content'), new TreeDropdownField('FeatureOneLinkID', 'Page to link to', 'SiteTree'), new TextField('FeatureOneButtonText', 'Button text')))->setHeadingLevel(3)); $fields->addFieldToTab('Root.Features', ToggleCompositeField::create('FeatureTwo', _t('SiteTree.FeatureTwo', 'Feature Two'), array(new TextField('FeatureTwoTitle', 'Title'), new DropdownField('FeatureTwoCategory', 'Category', singleton('ExpressHomePage')->dbObject('FeatureTwoCategory')->enumValues()), new HTMLEditorField('FeatureTwoContent', 'Content'), new TreeDropdownField('FeatureTwoLinkID', 'Page to link to', 'SiteTree'), new TextField('FeatureTwoButtonText', 'Button text')))->setHeadingLevel(3)); return $fields; }
public function updateCMSFields(FieldList $fields) { foreach (['primary', 'secondary'] as $lower) { $upper = ucfirst($lower); $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'); $rootTab->push($tab = Tab::create("{$upper}Gallery")); if ($rootTab->fieldByName('Metadata')) { $metaChildren = $rootTab->fieldByName('Metadata')->getChildren(); $rootTab->removeByName('Metadata'); $rootTab->push(Tab::create('Metadata')->setChildren($metaChildren)); } $tab->setTitle($config['title']); $fields->addFieldToTab("Root.{$upper}Gallery", $GridField); } }
/** * Get CMS Fields * * @return FieldList */ public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName('Images'); $fields->removeFieldsFromTab('Root.Main', array('BackgroundImage')); $gridFieldBulkUpload = new GridFieldBulkUpload(); $gridFieldBulkUpload->setUfSetup('setFolderName', 'GalleryImages/' . $this->ID); $fields->insertBefore(GridField::create('Images', 'Images', $this->Images(), GridFieldConfig_RecordEditor::create()->addComponent(new GridFieldSortableRows('SortOrder'))->addComponent($gridFieldBulkUpload)), 'ExtraClassDescriptionContainer'); return $fields; }
/** * Updates the Upload/Attach response from the UploadField * with the new DataObject records for the JS template * * @param DataObject $record Newly create DataObject record * @param array $uploadResponse Upload or Attach response from UploadField * @return array Updated $uploadResponse with $record data */ protected function newRecordJSTemplateData(DataObject &$record, &$uploadResponse) { // fetch uploadedFile record and sort out previewURL // update $uploadResponse datas in case changes happened onAfterWrite() $uploadedFile = DataObject::get_by_id($this->component->getFileRelationClassName($this->gridField), $uploadResponse['id']); if ($uploadedFile) { $uploadResponse['name'] = $uploadedFile->Name; $uploadResponse['url'] = $uploadedFile->getURL(); if ($uploadedFile instanceof Image) { $uploadResponse['thumbnail_url'] = $uploadedFile->CroppedImage(30, 30)->getURL(); } else { $uploadResponse['thumbnail_url'] = $uploadedFile->Icon(); } // check if our new record has a Title, if not create one automatically $title = $record->getTitle(); if (!$title || $title === $record->ID) { if ($record->hasDatabaseField('Title')) { $record->Title = $uploadedFile->Title; $record->write(); } else { if ($record->hasDatabaseField('Name')) { $record->Name = $uploadedFile->Title; $record->write(); } } } } // Collect all data for JS template $return = array_merge($uploadResponse, array('record' => array('id' => $record->ID))); return $return; }
/** * Retrieve Files to be attached * and generated DataObjects for each one. * * @param SS_HTTPRequest $request * * @return SS_HTTPResponse */ public function attach(SS_HTTPRequest $request) { $uploadField = $this->getUploadField(); $attachResponses = $uploadField->attach($request); $attachResponses = json_decode($attachResponses->getBody(), true); $fileRelationName = $uploadField->getName(); $recordClass = $this->component->getRecordClassName($this->gridField); $return = array(); foreach ($attachResponses as $attachResponse) { // create record $record = Object::create($recordClass); $record->write(); $record->extend('onBulkUpload', $this->gridField); // attach file $record->{"{$fileRelationName}ID"} = $attachResponse['id']; $record->write(); // attached record to gridField relation $this->gridField->list->add($record->ID); // JS Template Data $responseData = $this->newRecordJSTemplateData($record, $attachResponse); // add to returned dataset array_push($return, $responseData); } $response = new SS_HTTPResponse(Convert::raw2json($return)); $this->contentTypeNegotiation($response); return $response; }
public function getCMSFields() { $fields = parent::getCMSFields(); $gridFieldConfig = GridFieldConfig_RecordEditor::create(); //$gridFieldConfig->addComponent(new GridFieldBulkEditingTools()); $gridFieldConfig->addComponent($gbu = new GridFieldBulkUpload()); $editableFields = array('Title', 'Caption', 'Aperture', 'ShutterSpeed', 'Image'); $gridFieldConfig->addComponent($gbm = new GridFieldBulkManager($editableFields)); $gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder')); $galleryimagesi18n = _t('GalleryImage.PLURALNAME', 'Gallery Images'); //$gbu->setConfig('fileRelationName','Image'); $gbu->setUfConfig('folderName', 'galleries/' . $this->ID); $gbm->setConfig('editableFields', $editableFields); // This is no longer available... $gbm->setConfig('fieldsNameBlacklist', array('Lat', 'Lon', 'ZoomLevel')); $gridfield = new GridField('GalleryImages', $galleryimagesi18n, $this->GalleryImages()->sort('"SortOrder"'), $gridFieldConfig); $fields->addFieldToTab('Root.' . $galleryimagesi18n, $gridfield); $fields->addFieldToTab('Root.Date', new DateField('GalleryDate')); return $fields; }
public function getCMSFields() { if ($this->ID == 0) { $PhotosGridField = TextField::create('PhotosDisclaimer')->setTitle('Photos')->setDisabled(true)->setValue('You can add photos once you have saved the record for the first time.'); $ImageField = TextField::create('AlbumCoverDisclaimer')->setTitle('Album Cover Photo')->setDisabled(true)->setValue('You can add an album cover once you have saved the record for the first time.'); } else { $BulkUploadComponent = new GridFieldBulkUpload(); $BulkUploadComponent->setUfSetup('setFolderName', "photogallery/" . $this->PageFolder() . "/" . $this->AlbumFolder()); $PhotosGridField = new GridField('PhotoItems', 'Photos', $this->PhotoItems(), GridFieldConfig::create()->addComponent(new GridFieldToolbarHeader())->addComponent(new GridFieldAddNewButton("toolbar-header-right"))->addComponent(new GridFieldSortableHeader())->addComponent(new GridFieldDataColumns())->addComponent(new GridFieldPaginator(50))->addComponent(new GridFieldEditButton())->addComponent(new GridFieldDeleteAction())->addComponent(new GridFieldDetailForm())->addComponent(new GridFieldFilterHeader())->addComponent(new GridFieldBulkManager())->addComponent($BulkUploadComponent)->addComponent($sortable = new GridFieldSortableRows('SortID'))); if ($this->getComponent('PhotoGallery')->PhotoDefaultTop == true) { $sortable->setAppendToTop(true); } $ImageField = UploadField::create('AlbumCover')->setTitle('Album Cover Photo'); $ImageField->folderName = 'photogallery/' . $this->PageFolder(); $ImageField->getValidator()->allowedExtensions = array("jpg", "jpeg", "gif", "png"); } $Fields = new FieldList(TextField::create('Name'), TextareaField::create('Description'), $ImageField, $PhotosGridField); $this->extend('updateCMSFields', $Fields); return $Fields; }
public function updateCMSFields(FieldList $fields) { $sortable = singleton('CleanFile')->hasExtension('SortableDataExtension'); $config = GridFieldConfig_RelationEditor::create(); $config->addComponent($gridFieldForm = new GridFieldDetailForm()); if ($sortable) { $config->addComponent(new GridFieldSortableRows('SortOrder')); } $iu = new GridFieldBulkUpload('Attachment'); if (singleton('CleanFile')->hasExtension('ControlledFolderDataExtension')) { $iu->setUfConfig('folderName', singleton('CleanFile')->getUploadFolder()); } else { $iu->setUfConfig('folderName', CleanFile::$upload_folder); } $config->addComponent($iu); if ($sortable) { $data = $this->owner->CleanFiles("ClassName = 'CleanFile'")->sort('SortOrder'); } else { $data = $this->owner->CleanFiles("ClassName = 'CleanFile'"); } $fields->addFieldToTab("Root.Files", GridField::create('CleanFiles', 'CleanFile', $data, $config)); }
public function getCMSFields() { // If the album is not created yet, ask first for an album title to create the folder if (!$this->ID) { $fields = new FieldList(); $fields->push(new TextField('AlbumName', _t('MagnificGalleryAlbum.ALBUMTITLE', 'Album Title'), null, 255)); $fields->push(new LiteralField('AlbumSaveInfos', _t('MagnificGalleryAlbum.ALBUMSAVEINFOS', 'You can add images and a description once the album is saved'), null, 255)); return $fields; } $fields = new FieldList(new TabSet('Root')); // 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('GridFieldBulkUpload')) { $galleryConfig->addComponents($imageConfig = new GridFieldBulkUpload('Image')); $imageConfig->setUfSetup('setFolderName', $this->getUploadFolder()); } // Enable image sorting if necessary module is installed // @see composer.json/suggests if (class_exists('GridFieldSortableRows')) { $galleryConfig->addComponent(new GridFieldSortableRows('SortOrder')); } else { if (class_exists('GridFieldOrderableRows')) { $galleryConfig->addComponent(new GridFieldOrderableRows('SortOrder')); } } $galleryField = new GridField('GalleryItems', 'Gallery Items', $this->GalleryItems(), $galleryConfig); $fields->addFieldToTab('Root.Main', $galleryField); // Details $thumbnailField = new UploadField('CoverImage', _t('MagnificGalleryAlbum.COVERIMAGE', 'Cover Image')); $thumbnailField->getValidator()->setAllowedExtensions(File::config()->app_categories['image']); $thumbnailField->setFolderName($this->getUploadFolder()); $fields->addFieldsToTab('Root.Album', array(new TextField('AlbumName', _t('MagnificGalleryAlbum.ALBUMTITLE', 'Album Title'), null, 255), new TextareaField('Description', _t('MagnificGalleryAlbum.DESCRIPTION', 'Description')), $thumbnailField)); return $fields; }