mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #6050 from open-sausages/pulls/4.0/highlighted-file-tweak
API Move PreviewLink logic into File dataobject
This commit is contained in:
commit
c36d947faa
@ -473,8 +473,7 @@ class File extends DataObject implements ShortcodeHandler, AssetContainer, Thumb
|
|||||||
public function getCMSFields() {
|
public function getCMSFields() {
|
||||||
$path = '/' . dirname($this->getFilename());
|
$path = '/' . dirname($this->getFilename());
|
||||||
|
|
||||||
$width = (int)Image::config()->get('asset_preview_width');
|
$previewLink = Convert::raw2att($this->PreviewLink());
|
||||||
$previewLink = Convert::raw2att($this->ScaleMaxWidth($width)->getIcon());
|
|
||||||
$image = "<img src=\"{$previewLink}\" class=\"editor__thumbnail\" />";
|
$image = "<img src=\"{$previewLink}\" class=\"editor__thumbnail\" />";
|
||||||
|
|
||||||
$content = Tab::create('Main',
|
$content = Tab::create('Main',
|
||||||
@ -1219,8 +1218,12 @@ class File extends DataObject implements ShortcodeHandler, AssetContainer, Thumb
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function PreviewLink($action = null) {
|
public function PreviewLink($action = null) {
|
||||||
// No preview for non-images by default
|
// Since AbsoluteURL can whitelist protected assets,
|
||||||
$link = null;
|
// do permission check first
|
||||||
|
if (!$this->canView()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$link = $this->getIcon();
|
||||||
$this->extend('updatePreviewLink', $link, $action);
|
$this->extend('updatePreviewLink', $link, $action);
|
||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
@ -47,12 +47,7 @@ class Image extends File implements ShortcodeHandler {
|
|||||||
public function getCMSFields() {
|
public function getCMSFields() {
|
||||||
$path = '/' . dirname($this->getFilename());
|
$path = '/' . dirname($this->getFilename());
|
||||||
|
|
||||||
$width = (int)Image::config()->get('asset_preview_width');
|
$previewLink = Convert::raw2att($this->PreviewLink());
|
||||||
$height = (int)Image::config()->get('asset_preview_height');
|
|
||||||
$previewLink = Convert::raw2att($this
|
|
||||||
->FitMax($width, $height)
|
|
||||||
->PreviewLink()
|
|
||||||
);
|
|
||||||
$image = "<img src=\"{$previewLink}\" class=\"editor__thumbnail\" />";
|
$image = "<img src=\"{$previewLink}\" class=\"editor__thumbnail\" />";
|
||||||
|
|
||||||
$link = $this->Link();
|
$link = $this->Link();
|
||||||
@ -215,7 +210,16 @@ class Image extends File implements ShortcodeHandler {
|
|||||||
if(!$this->canView()) {
|
if(!$this->canView()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$link = $this->AbsoluteLink();
|
|
||||||
|
// Size to width / height
|
||||||
|
$width = (int)$this->config()->get('asset_preview_width');
|
||||||
|
$height = (int)$this->config()->get('asset_preview_height');
|
||||||
|
$resized = $this->FitMax($width, $height);
|
||||||
|
if ($resized && $resized->exists()) {
|
||||||
|
$link = $resized->getAbsoluteURL();
|
||||||
|
} else {
|
||||||
|
$link = $this->getIcon();
|
||||||
|
}
|
||||||
$this->extend('updatePreviewLink', $link, $action);
|
$this->extend('updatePreviewLink', $link, $action);
|
||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
@ -529,27 +529,4 @@ class DBFile extends DBComposite implements AssetContainer, Thumbnail {
|
|||||||
->getStore()
|
->getStore()
|
||||||
->canView($this->Filename, $this->Hash);
|
->canView($this->Filename, $this->Hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates the URL for this DBFile preview, this is particularly important for images that
|
|
||||||
* have been manipulated e.g. by {@link ImageManipulation}
|
|
||||||
* Use the 'updatePreviewLink' extension point to customise the link.
|
|
||||||
*
|
|
||||||
* @param null $action
|
|
||||||
* @return bool|string
|
|
||||||
*/
|
|
||||||
public function PreviewLink($action = null) {
|
|
||||||
// Since AbsoluteURL can whitelist protected assets,
|
|
||||||
// do permission check first
|
|
||||||
if (!$this->failover->canView()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($this->getIsImage()) {
|
|
||||||
$link = $this->getAbsoluteURL();
|
|
||||||
} else {
|
|
||||||
$link = Convert::raw2att($this->failover->getIcon());
|
|
||||||
}
|
|
||||||
$this->extend('updatePreviewLink', $link, $action);
|
|
||||||
return $link;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user