1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Elements\FileList\Elements; |
4
|
|
|
|
5
|
|
|
use Colymba\BulkUpload\BulkUploader; |
|
|
|
|
6
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
7
|
|
|
use Dynamic\Elements\FileList\Model\FileListObject; |
8
|
|
|
use SilverStripe\Forms\FieldList; |
9
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; |
10
|
|
|
use SilverStripe\Forms\GridField\GridFieldDeleteAction; |
11
|
|
|
use SilverStripe\ORM\FieldType\DBField; |
12
|
|
|
use Symbiote\GridFieldExtensions\GridFieldOrderableRows; |
13
|
|
|
|
14
|
|
|
class ElementFileList extends BaseElement |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private static $icon = 'font-icon-block-file-list'; |
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private static $table_name = 'ElementFileList'; |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
private static $has_many = [ |
|
|
|
|
30
|
|
|
'Files' => FileListObject::class, |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
private static $owns = [ |
|
|
|
|
37
|
|
|
'Files', |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var bool |
42
|
|
|
*/ |
43
|
|
|
private static $inline_editable = false; |
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param bool $includerelations |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
|
|
public function fieldLabels($includerelations = true) |
50
|
|
|
{ |
51
|
|
|
$labels = parent::fieldLabels($includerelations); |
52
|
|
|
|
53
|
|
|
$labels['Files'] = _t(__CLASS__.'.FilesLabel', 'Files'); |
54
|
|
|
|
55
|
|
|
return $labels; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return FieldList |
60
|
|
|
*/ |
61
|
|
|
public function getCMSFields() |
62
|
|
|
{ |
63
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
64
|
|
|
if ($this->ID) { |
65
|
|
|
$field = $fields->dataFieldByName('Files'); |
66
|
|
|
$fields->removeByName('Files'); |
67
|
|
|
|
68
|
|
|
$config = $field->getConfig(); |
69
|
|
|
$config |
70
|
|
|
->addComponents([ |
71
|
|
|
new GridFieldOrderableRows('SortOrder') |
72
|
|
|
]) |
73
|
|
|
->removeComponentsByType([ |
74
|
|
|
GridFieldAddExistingAutocompleter::class, |
75
|
|
|
GridFieldDeleteAction::class |
76
|
|
|
]); |
77
|
|
|
if (class_exists(BulkUploader::class)) { |
78
|
|
|
$config->addComponents([ |
79
|
|
|
new BulkUploader() |
80
|
|
|
]); |
81
|
|
|
$config->getComponentByType(BulkUploader::class) |
82
|
|
|
->setUfSetup('setFolderName', 'Uploads/FileList'); |
83
|
|
|
} |
84
|
|
|
$fields->addFieldToTab('Root.Main', $field); |
85
|
|
|
} |
86
|
|
|
}); |
87
|
|
|
|
88
|
|
|
return parent::getCMSFields(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return DBHTMLText |
|
|
|
|
93
|
|
|
*/ |
94
|
|
|
public function getSummary() |
95
|
|
|
{ |
96
|
|
|
if ($this->Files()->count() == 1) { |
|
|
|
|
97
|
|
|
$label = ' file'; |
98
|
|
|
} else { |
99
|
|
|
$label = ' files'; |
100
|
|
|
} |
101
|
|
|
return DBField::create_field('HTMLText', $this->Files()->count() . $label)->Summary(20); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
protected function provideBlockSchema() |
108
|
|
|
{ |
109
|
|
|
$blockSchema = parent::provideBlockSchema(); |
110
|
|
|
$blockSchema['content'] = $this->getSummary(); |
111
|
|
|
return $blockSchema; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
public function getType() |
118
|
|
|
{ |
119
|
|
|
return _t(__CLASS__.'.BlockType', 'File List'); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
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