/** * Returns the fields to power the edit screen of files in the CMS. * You can modify this FieldList by subclassing folder, or by creating a {@link DataExtension} * and implemeting updateCMSFields(FieldList $fields) on that extension. * * @return FieldList */ public function getCMSFields() { // Preview if ($this instanceof Image) { $formattedImage = $this->getFormattedImage('SetWidth', Config::inst()->get('Image', 'asset_preview_width')); $thumbnail = $formattedImage ? $formattedImage->URL : ''; $previewField = new LiteralField("ImageFull", "<img id='thumbnailImage' class='thumbnail-preview' src='{$thumbnail}?r=" . rand(1, 100000) . "' alt='{$this->Name}' />\n"); } else { $previewField = new LiteralField("ImageFull", $this->CMSThumbnail()); } // Upload $uploadField = UploadField::create('UploadField', 'Upload Field')->setPreviewMaxWidth(40)->setPreviewMaxHeight(30)->setAllowedMaxFileNumber(1); //$uploadField->setTemplate('FileEditUploadField'); if ($this->ParentID) { $parent = $this->Parent(); if ($parent) { //set the parent that the Upload field should use for uploads $uploadField->setFolderName($parent->getFilename()); $uploadField->setRecord($parent); } } //create the file attributes in a FieldGroup $filePreview = CompositeField::create(CompositeField::create($previewField)->setName("FilePreviewImage")->addExtraClass('cms-file-info-preview'), CompositeField::create(CompositeField::create(new ReadonlyField("FileType", _t('AssetTableField.TYPE', 'File type') . ':'), new ReadonlyField("Size", _t('AssetTableField.SIZE', 'File size') . ':', $this->getSize()), $urlField = new ReadonlyField('ClickableURL', _t('AssetTableField.URL', 'URL'), sprintf('<a href="%s" target="_blank">%s</a>', $this->Link(), $this->RelativeLink())), new DateField_Disabled("Created", _t('AssetTableField.CREATED', 'First uploaded') . ':'), new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT', 'Last changed') . ':')))->setName("FilePreviewData")->addExtraClass('cms-file-info-data'))->setName("FilePreview")->addExtraClass('cms-file-info'); $urlField->dontEscape = true; //get a tree listing with only folder, no files $folderTree = new TreeDropdownField("ParentID", _t('AssetTableField.FOLDER', 'Folder'), 'Folder'); $folderTree->setChildrenMethod('ChildFolders'); $fields = new FieldList(new TabSet('Root', new Tab('Main', $filePreview, new TextField("Title", _t('AssetTableField.TITLE', 'Title')), new TextField("Name", _t('AssetTableField.FILENAME', 'Filename')), new DropdownField("OwnerID", _t('AssetTableField.OWNER', 'Owner'), Member::mapInCMSGroups()), $folderTree))); // Folder has its own updateCMSFields hook if (!$this instanceof Folder) { $this->extend('updateCMSFields', $fields); } return $fields; }