Merge pull request #5934 from open-sausages/pulls/4.0/file-folder-getCMSFields

API Adapt File/Folder getCMSFields() to new AssetAdmin
This commit is contained in:
Daniel Hensby 2016-08-31 23:26:33 +01:00 committed by GitHub
commit f57d6b377e
2 changed files with 41 additions and 46 deletions

View File

@ -447,50 +447,46 @@ class File extends DataObject implements ShortcodeHandler, AssetContainer, Thumb
/** /**
* Returns the fields to power the edit screen of files in the CMS. * 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} * You can modify this FieldList by subclassing folder, or by creating a {@link DataExtension}
* and implemeting updateCMSFields(FieldList $fields) on that extension. * and implementing updateCMSFields(FieldList $fields) on that extension.
* *
* @return FieldList * @return FieldList
*/ */
public function getCMSFields() { public function getCMSFields() {
// Preview $path = '/' . dirname($this->getFilename());
$filePreview = CompositeField::create(
CompositeField::create(new LiteralField("ImageFull", $this->PreviewThumbnail())) $fields = FieldList::create([
->setName("FilePreviewImage") HeaderField::create('TitleHeader', $this->Title, 1),
->addExtraClass('cms-file-info-preview'), LiteralField::create("ImageFull", $this->PreviewThumbnail()),
CompositeField::create( TextField::create("Name", $this->fieldLabel('Filename')),
CompositeField::create( ReadonlyField::create(
new ReadonlyField("FileType", _t('AssetTableField.TYPE','File type') . ':'), "Path",
new ReadonlyField("Size", _t('AssetTableField.SIZE','File size') . ':', $this->getSize()), _t('AssetTableField.PATH', 'Path'),
HTMLReadonlyField::create( (($path !== '/.') ? $path : '') . '/'
)
]);
if ($this->getIsImage()) {
$fields->push(ReadonlyField::create(
"DisplaySize",
_t('AssetTableField.SIZE', "File size"),
sprintf('%spx, %s', $this->getDimensions(), $this->getSize())
));
$fields->push(HTMLReadonlyField::create(
'ClickableURL', 'ClickableURL',
_t('AssetTableField.URL','URL'), _t('AssetTableField.URL','URL'),
sprintf('<a href="%s" target="_blank">%s</a>', $this->Link(), $this->Link()) sprintf('<a href="%s" target="_blank">%s</a>', $this->Link(), $this->Link())
), ));
new DateField_Disabled("Created", _t('AssetTableField.CREATED','First uploaded') . ':'), }
new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT','Last changed') . ':') $fields->push(HiddenField::create('ID', $this->ID));
)
)
->setName("FilePreviewData")
->addExtraClass('cms-file-info-data')
)
->setName("FilePreview")
->addExtraClass('cms-file-info');
//get a tree listing with only folder, no files $fields->insertBefore(TextField::create("Title", $this->fieldLabel('Title')), 'Name');
$fields = new FieldList( $fields->push(DatetimeField::create(
new TabSet('Root', "LastEdited",
new Tab('Main', _t('AssetTableField.LASTEDIT', 'Last changed')
$filePreview, )->setReadonly(true));
new TextField("Title", _t('AssetTableField.TITLE','Title')),
new TextField("Name", _t('AssetTableField.FILENAME','Filename')),
DropdownField::create("OwnerID", _t('AssetTableField.OWNER','Owner'), Member::mapInCMSGroups())
->setHasEmptyDefault(true),
new TreeDropdownField("ParentID", _t('AssetTableField.FOLDER','Folder'), 'Folder')
)
)
);
$this->extend('updateCMSFields', $fields); $this->extend('updateCMSFields', $fields);
return $fields; return $fields;
} }

View File

@ -181,17 +181,16 @@ class Folder extends File {
* @return FieldList * @return FieldList
*/ */
public function getCMSFields() { public function getCMSFields() {
// Hide field on root level, which can't be renamed // Don't show readonly path until we can implement parent folder selection,
if(!$this->ID || $this->ID === "root") { // it's too confusing when readonly (makes sense for files only).
$titleField = new HiddenField("Name");
} else { $fields = FieldList::create([
$titleField = new TextField("Name", $this->fieldLabel('Name')); HeaderField::create('TitleHeader', $this->Title, 1),
} LiteralField::create("ImageFull", $this->PreviewThumbnail()),
TextField::create("Name", $this->fieldLabel('Filename')),
HiddenField::create('ID', $this->ID)
]);
$fields = new FieldList(
$titleField,
new HiddenField('ParentID')
);
$this->extend('updateCMSFields', $fields); $this->extend('updateCMSFields', $fields);
return $fields; return $fields;