1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ElementalFileBlock\Block; |
4
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
6
|
|
|
use SilverStripe\AssetAdmin\Forms\UploadField; |
|
|
|
|
7
|
|
|
use SilverStripe\Assets\File; |
8
|
|
|
use SilverStripe\Assets\Image_Backend; |
9
|
|
|
use SilverStripe\Core\Manifest\ModuleResourceLoader; |
10
|
|
|
use SilverStripe\Forms\FieldList; |
11
|
|
|
use SilverStripe\ORM\FieldType\DBHTMLText; |
12
|
|
|
|
13
|
|
|
class FileBlock extends BaseElement |
14
|
|
|
{ |
15
|
|
|
private static $has_one = [ |
|
|
|
|
16
|
|
|
'File' => File::class, |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
private static $owns = [ |
|
|
|
|
20
|
|
|
'File', |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
private static $singular_name = 'file'; |
|
|
|
|
24
|
|
|
|
25
|
|
|
private static $plural_name = 'files'; |
|
|
|
|
26
|
|
|
|
27
|
|
|
private static $icon = 'font-icon-block-file'; |
|
|
|
|
28
|
|
|
|
29
|
|
|
private static $table_name = 'S_EB_FileBlock'; |
|
|
|
|
30
|
|
|
|
31
|
|
|
public function getCMSFields() |
32
|
|
|
{ |
33
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
34
|
|
|
/** @var UploadField $uploadField */ |
35
|
|
|
$uploadField = $fields->fieldByName('Root.Main.File'); |
36
|
|
|
$uploadField->setIsMultiUpload(false); |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
return parent::getCMSFields(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getType() |
43
|
|
|
{ |
44
|
|
|
return _t(__CLASS__ . '.BlockType', 'File'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getSummary() |
48
|
|
|
{ |
49
|
|
|
if ($this->File() && $this->File()->exists()) { |
|
|
|
|
50
|
|
|
return $this->getSummaryThumbnail() . $this->File()->Title; |
51
|
|
|
} |
52
|
|
|
return ''; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Return file title and thumbnail for summary section of ElementEditor |
57
|
|
|
* |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
protected function provideBlockSchema() |
61
|
|
|
{ |
62
|
|
|
$blockSchema = parent::provideBlockSchema(); |
63
|
|
|
if ($this->File() && $this->File()->exists() && $this->File()->getIsImage()) { |
64
|
|
|
$blockSchema['fileURL'] = $this->File()->CMSThumbnail()->getURL(); |
65
|
|
|
$blockSchema['fileTitle'] = $this->File()->getTitle(); |
66
|
|
|
} |
67
|
|
|
return $blockSchema; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Return a thumbnail of the file, if it's an image. Used in GridField preview summaries. |
72
|
|
|
* |
73
|
|
|
* @return DBHTMLText |
74
|
|
|
*/ |
75
|
|
|
public function getSummaryThumbnail() |
76
|
|
|
{ |
77
|
|
|
$data = []; |
78
|
|
|
|
79
|
|
|
if ($this->File() && $this->File()->exists()) { |
80
|
|
|
if ($this->File()->getIsImage()) { |
81
|
|
|
// Stretch to maximum of 36px either way then trim the extra off |
82
|
|
|
if ($this->File()->getOrientation() === Image_Backend::ORIENTATION_PORTRAIT) { |
83
|
|
|
$data['Image'] = $this->File()->ScaleWidth(36)->CropHeight(36); |
84
|
|
|
} else { |
85
|
|
|
$data['Image'] = $this->File()->ScaleHeight(36)->CropWidth(36); |
86
|
|
|
} |
87
|
|
|
} else { |
88
|
|
|
$data = [ |
89
|
|
|
'Image' => ModuleResourceLoader::resourceURL( |
90
|
|
|
'silverstripe/framework:client/images/app_icons/document_92.png' |
91
|
|
|
), |
92
|
|
|
'IsPlaceholder' => true |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $this->customise($data)->renderWith(__CLASS__ . '/SummaryThumbnail'); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths