mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
commit
f57d6b377e
@ -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()))
|
|
||||||
->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()),
|
|
||||||
HTMLReadonlyField::create(
|
|
||||||
'ClickableURL',
|
|
||||||
_t('AssetTableField.URL','URL'),
|
|
||||||
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') . ':')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
->setName("FilePreviewData")
|
|
||||||
->addExtraClass('cms-file-info-data')
|
|
||||||
)
|
|
||||||
->setName("FilePreview")
|
|
||||||
->addExtraClass('cms-file-info');
|
|
||||||
|
|
||||||
//get a tree listing with only folder, no files
|
$fields = FieldList::create([
|
||||||
$fields = new FieldList(
|
HeaderField::create('TitleHeader', $this->Title, 1),
|
||||||
new TabSet('Root',
|
LiteralField::create("ImageFull", $this->PreviewThumbnail()),
|
||||||
new Tab('Main',
|
TextField::create("Name", $this->fieldLabel('Filename')),
|
||||||
$filePreview,
|
ReadonlyField::create(
|
||||||
new TextField("Title", _t('AssetTableField.TITLE','Title')),
|
"Path",
|
||||||
new TextField("Name", _t('AssetTableField.FILENAME','Filename')),
|
_t('AssetTableField.PATH', 'Path'),
|
||||||
DropdownField::create("OwnerID", _t('AssetTableField.OWNER','Owner'), Member::mapInCMSGroups())
|
(($path !== '/.') ? $path : '') . '/'
|
||||||
->setHasEmptyDefault(true),
|
|
||||||
new TreeDropdownField("ParentID", _t('AssetTableField.FOLDER','Folder'), 'Folder')
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
]);
|
||||||
|
|
||||||
|
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',
|
||||||
|
_t('AssetTableField.URL','URL'),
|
||||||
|
sprintf('<a href="%s" target="_blank">%s</a>', $this->Link(), $this->Link())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$fields->push(HiddenField::create('ID', $this->ID));
|
||||||
|
|
||||||
|
$fields->insertBefore(TextField::create("Title", $this->fieldLabel('Title')), 'Name');
|
||||||
|
$fields->push(DatetimeField::create(
|
||||||
|
"LastEdited",
|
||||||
|
_t('AssetTableField.LASTEDIT', 'Last changed')
|
||||||
|
)->setReadonly(true));
|
||||||
|
|
||||||
$this->extend('updateCMSFields', $fields);
|
$this->extend('updateCMSFields', $fields);
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user