1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Handles requests for creating or editing actions. |
4
|
|
|
* |
5
|
|
|
* @package silverstripe-advancedworkflow |
6
|
|
|
*/ |
7
|
|
|
class WorkflowFieldActionController extends RequestHandler { |
|
|
|
|
8
|
|
|
|
9
|
|
|
public static $url_handlers = array( |
10
|
|
|
'new/$Class' => 'handleAdd', |
11
|
|
|
'item/$ID' => 'handleItem' |
12
|
|
|
); |
13
|
|
|
|
14
|
|
|
public static $allowed_actions = array( |
15
|
|
|
'handleAdd', |
16
|
|
|
'handleItem' |
17
|
|
|
); |
18
|
|
|
|
19
|
|
|
protected $parent; |
20
|
|
|
protected $name; |
21
|
|
|
|
22
|
|
|
public function __construct($parent, $name) { |
23
|
|
|
$this->parent = $parent; |
24
|
|
|
$this->name = $name; |
25
|
|
|
|
26
|
|
|
parent::__construct(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function handleAdd() { |
30
|
|
|
$class = $this->request->param('Class'); |
31
|
|
|
|
32
|
|
|
if(!class_exists($class) || !is_subclass_of($class, 'WorkflowAction')) { |
33
|
|
|
$this->httpError(400); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$reflector = new ReflectionClass($class); |
37
|
|
|
|
38
|
|
|
if($reflector->isAbstract() || !singleton($class)->canCreate()) { |
39
|
|
|
$this->httpError(400); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$record = new $class(); |
43
|
|
|
$record->WorkflowDefID = $this->parent->Definition()->ID; |
44
|
|
|
|
45
|
|
|
return new WorkflowFieldItemController($this, "new/$class", $record); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public function handleItem() { |
|
|
|
|
49
|
|
|
$id = $this->request->param('ID'); |
50
|
|
|
$defn = $this->parent->Definition(); |
51
|
|
|
$action = $defn->Actions()->byID($id); |
52
|
|
|
|
53
|
|
|
if(!$action) { |
54
|
|
|
$this->httpError(404); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if(!$action->canEdit()) { |
58
|
|
|
$this->httpError(403); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return new WorkflowFieldItemController($this, "item/$id", $action); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function RootField() { |
65
|
|
|
return $this->parent; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function Link($action = null) { |
69
|
|
|
return Controller::join_links($this->parent->Link(), $this->name, $action); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.