|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AntonyThorpe\SilverShopProductImages; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Core\Extension; |
|
|
|
|
|
|
6
|
|
|
use SilverStripe\ORM\ManyManyList; |
|
|
|
|
|
|
7
|
|
|
use SilverShop\Page\Product; |
|
|
|
|
|
|
8
|
|
|
use SilverStripe\Forms\FieldList; |
|
|
|
|
|
|
9
|
|
|
use SilverStripe\Assets\Image; |
|
|
|
|
|
|
10
|
|
|
use SilverStripe\Forms\LiteralField; |
|
|
|
|
|
|
11
|
|
|
use SilverStripe\ORM\ArrayList; |
|
|
|
|
|
|
12
|
|
|
use SilverStripe\ORM\DataList; |
|
|
|
|
|
|
13
|
|
|
use Bummzack\SortableFile\Forms\SortableUploadField; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Extends SilverShop\Page\Product |
|
17
|
|
|
* @method ManyManyList<Image> AdditionalImages() |
|
18
|
|
|
* @extends Extension<(Product & static)> |
|
19
|
|
|
*/ |
|
20
|
|
|
class ProductImages extends Extension |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @config |
|
24
|
|
|
*/ |
|
25
|
|
|
private static array $many_many = [ |
|
|
|
|
|
|
26
|
|
|
'AdditionalImages' => Image::class, |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @config |
|
31
|
|
|
*/ |
|
32
|
|
|
private static array $many_many_extraFields = [ |
|
|
|
|
|
|
33
|
|
|
'AdditionalImages' => ['SortOrder' => 'Int'], |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
public function updateCMSFields(FieldList $fieldList): void |
|
37
|
|
|
{ |
|
38
|
|
|
$newfields = [ |
|
39
|
|
|
SortableUploadField::create( |
|
40
|
|
|
'AdditionalImages', |
|
41
|
|
|
_t(self::class . '.AdditionalImages', 'Additional Images') |
|
|
|
|
|
|
42
|
|
|
), |
|
43
|
|
|
LiteralField::create( |
|
44
|
|
|
'additionalimagesinstructions', |
|
45
|
|
|
'<p>' . _t(self::class . '.Instructions', 'You can change the order of the Additional Images by clicking and dragging on the image thumbnail.') . '</p>' |
|
46
|
|
|
) |
|
47
|
|
|
]; |
|
48
|
|
|
if ($fieldList->hasTabset()) { |
|
49
|
|
|
$fieldList->addFieldsToTab('Root.Images', $newfields); |
|
50
|
|
|
} else { |
|
51
|
|
|
foreach ($newfields as $newfield) { |
|
52
|
|
|
$fieldList->push($newfield); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Combines the main image and the secondary images |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getAllImages(): ArrayList |
|
61
|
|
|
{ |
|
62
|
|
|
$arrayList = ArrayList::create( |
|
63
|
|
|
$this->getOwner()->AdditionalImages()->sort('SortOrder')->toArray() |
|
64
|
|
|
); |
|
65
|
|
|
$main = $this->getOwner()->Image(); |
|
66
|
|
|
if ($main->exists()) { |
|
67
|
|
|
$arrayList->unshift($main); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $arrayList; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Sorted images |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getSortedAdditionalImages(): DataList |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->getOwner()->AdditionalImages()->sort('SortOrder'); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
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