1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Terranet\Administrator\Field; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\View; |
6
|
|
|
use Spatie\MediaLibrary\Models\Media; |
|
|
|
|
7
|
|
|
use Terranet\Administrator\Field\Traits\WorksWithModules; |
8
|
|
|
use Terranet\Administrator\Scaffolding; |
9
|
|
|
|
10
|
|
|
class MediaCollection extends Generic |
11
|
|
|
{ |
12
|
|
|
use WorksWithModules; |
13
|
|
|
|
14
|
|
|
protected $conversion = ''; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param string $conversion |
18
|
|
|
* @return self |
19
|
|
|
*/ |
20
|
|
|
public function convertedTo(string $conversion): self |
21
|
|
|
{ |
22
|
|
|
$this->conversion = $conversion; |
23
|
|
|
|
24
|
|
|
return $this; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return \Illuminate\Contracts\View\View |
29
|
|
|
*/ |
30
|
|
|
protected function onIndex() |
31
|
|
|
{ |
32
|
|
|
$media = $this->model->getMedia( |
33
|
|
|
$name = $this->id() |
34
|
|
|
); |
35
|
|
|
$module = $this->firstWithModel($this->model); |
36
|
|
|
|
37
|
|
|
return [ |
|
|
|
|
38
|
|
|
'media' => $media, |
39
|
|
|
'module' => $module ?: app('scaffold.module'), |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return \Illuminate\Contracts\View\View |
45
|
|
|
*/ |
46
|
|
|
protected function onView() |
47
|
|
|
{ |
48
|
|
|
$media = $this->model->getMedia( |
49
|
|
|
$name = $this->id() |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$media = $media->map(function ($item) { |
53
|
|
|
return array_merge($item->toArray(), [ |
54
|
|
|
'url' => $item->getUrl(), |
55
|
|
|
'conversions' => $this->conversions($item), |
56
|
|
|
]); |
57
|
|
|
}); |
58
|
|
|
|
59
|
|
|
return [ |
|
|
|
|
60
|
|
|
'media' => $media->toJson(), |
61
|
|
|
'conversion' => $this->conversion, |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return \Illuminate\Contracts\View\View |
67
|
|
|
*/ |
68
|
|
|
protected function onEdit() |
69
|
|
|
{ |
70
|
|
|
$media = $this->model->getMedia( |
71
|
|
|
$name = $this->id() |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$media = $media->map(function ($item) { |
75
|
|
|
return array_merge($item->toArray(), [ |
76
|
|
|
'url' => $item->getUrl(), |
77
|
|
|
'conversions' => $this->conversions($item), |
78
|
|
|
]); |
79
|
|
|
}); |
80
|
|
|
|
81
|
|
|
return [ |
|
|
|
|
82
|
|
|
'media' => $media->toJson(), |
83
|
|
|
'conversion' => $this->conversion, |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param Media $item |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
protected function conversions(Media $item) |
93
|
|
|
{ |
94
|
|
|
return array_build($item->getMediaConversionNames(), function ($key, $conversion) use ($item) { |
95
|
|
|
return [$conversion, $item->getUrl($conversion)]; |
96
|
|
|
}); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
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