-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkflow.php
More file actions
68 lines (59 loc) · 1.87 KB
/
Workflow.php
File metadata and controls
68 lines (59 loc) · 1.87 KB
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 Litepie\Workflow;
use Symfony\Component\Workflow\Workflow as SymfonyWorkflow;
use Closure;
class Workflow extends SymfonyWorkflow
{
public function transitions(object $subject, $workflow = null)
{
$transitions = $this->getEnabledTransitions($subject, $workflow);
$ret = [];
foreach ($transitions as $t) {
$ret[$t->getName()] = $t;
}
return $ret;
}
public function transition($transition)
{
$transitions = $this
->getDefinition()
->getTransitions($this);
foreach ($transitions as $t) {
if ($t->getName() == $transition) {
return $t;
}
}
return null;
}
public function form($transition)
{
$meta = $this->getMetadataStore()
->getTransitionMetadata($transition);
if (!isset($meta['form']['fields'])) {
return null;
}
$form = $meta['form']['fields'];
$item = collect($form)->map(function ($val) {
$val['label'] = trans($val['label']);
$val['placeholder'] = trans($val['placeholder']);
if (isset($val['options']) && is_callable($val['options']) && $val['options'] instanceof Closure) {
$val['options'] = call_user_func($val['options']);
}
return $val;
});
return $item;
}
public function previous($transition, $workflow = null)
{
$previousTransitions = [];
$froms = $transition->getFroms();
$transitions = $this->getDefinition()->getTransitions();
foreach ($transitions as $transition) {
$tos = $transition->getTos();
if (count(array_intersect($froms, $tos)) > 0) {
$previousTransitions[] = $transition;
}
}
return $previousTransitions;
}
}