forked from statamic/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoveAsset.php
68 lines (57 loc) · 1.56 KB
/
MoveAsset.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Statamic\Actions;
use Statamic\Contracts\Assets\Asset;
use Statamic\Facades\AssetContainer;
use Statamic\Facades\Blink;
class MoveAsset extends Action
{
public static function title()
{
return __('Move');
}
public function visibleTo($item)
{
return $item instanceof Asset;
}
public function authorize($user, $asset)
{
return $user->can('move', $asset);
}
public function buttonText()
{
/** @translation */
return 'Move Asset|Move :count Assets';
}
public function confirmationText()
{
/** @translation */
return 'Are you sure you want to move this asset?|Are you sure you want to move these :count assets?';
}
public function run($assets, $values)
{
$ids = $assets->each->move($values['folder'])->map->id()->all();
return [
'ids' => $ids,
];
}
protected function fieldItems()
{
$options = Blink::once('action-move-asset-folders', function () {
return AssetContainer::find($this->context['container'])
->assetFolders()
->mapWithKeys(function ($folder) {
return [$folder->path() => $folder->path()];
})
->prepend('/', '/')
->all();
});
return [
'folder' => [
'display' => __('Folder'),
'type' => 'select',
'options' => $options,
'validate' => 'required',
],
];
}
}