-
-
Notifications
You must be signed in to change notification settings - Fork 568
/
Copy pathAction.php
146 lines (118 loc) · 3.32 KB
/
Action.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
namespace Statamic\Actions;
use Illuminate\Contracts\Support\Arrayable;
use Statamic\Extend\HasFields;
use Statamic\Extend\HasHandle;
use Statamic\Extend\HasTitle;
use Statamic\Extend\RegistersItself;
abstract class Action implements Arrayable
{
use HasFields, HasHandle, HasTitle, RegistersItself;
protected static $binding = 'actions';
protected $items;
protected $confirm = true;
protected $dangerous = false;
protected $fields = [];
protected $context = [];
public function __construct()
{
$this->items = collect();
}
public function items($items)
{
$this->items = collect($items);
return $this;
}
public function visibleTo($item)
{
return true;
}
public function visibleToBulk($items)
{
$allowedOnItems = $items->filter(function ($item) {
return $this->visibleTo($item);
});
return $items->count() === $allowedOnItems->count();
}
public function authorize($user, $item)
{
return true;
}
public function authorizeBulk($user, $items)
{
$authorizedOnItems = $items->filter(function ($item) use ($user) {
return $this->authorize($user, $item);
});
return $items->count() === $authorizedOnItems->count();
}
public function context($context)
{
if (! isset($context['view'])) {
$context['view'] = 'list';
}
$this->context = $context;
return $this;
}
protected function fieldItems()
{
return $this->fields;
}
public function run($items, $values)
{
//
}
public function redirect($items, $values)
{
return false;
}
public function download($items, $values)
{
return false;
}
public function buttonText()
{
/** @translation */
return 'Run action|Run action on :count items';
}
public function confirmationText()
{
/** @translation */
return 'Are you sure you want to run this action?|Are you sure you want to run this action on :count items?';
}
public function warningText()
{
return null;
}
public function dirtyWarningText()
{
/** @translation */
return "Any unsaved changes will not be reflected in this action's behavior.";
}
public function bypassesDirtyWarning(): bool
{
return false;
}
public function requiresElevatedSession(): bool
{
return false;
}
public function toArray()
{
return [
'handle' => $this->handle(),
'title' => $this->title(),
'confirm' => $this->confirm,
'buttonText' => $this->buttonText(),
'confirmationText' => $this->confirmationText(),
'warningText' => $this->warningText(),
'dirtyWarningText' => $this->dirtyWarningText(),
'bypassesDirtyWarning' => $this->bypassesDirtyWarning(),
'requiresElevatedSession' => $this->requiresElevatedSession(),
'dangerous' => $this->dangerous,
'fields' => $this->fields()->toPublishArray(),
'values' => $this->fields()->preProcess()->values(),
'meta' => $this->fields()->meta(),
'context' => $this->context,
];
}
}