1 | <?php |
||
8 | class WorkflowField extends FormField { |
||
|
|||
9 | |||
10 | public static $allowed_actions = array( |
||
11 | 'action', |
||
12 | 'transition', |
||
13 | 'sort' |
||
14 | ); |
||
15 | |||
16 | protected $definition; |
||
17 | |||
18 | public function __construct($name, $title, WorkflowDefinition $definition) { |
||
19 | $this->definition = $definition; |
||
20 | $this->addExtraClass('workflow-field'); |
||
21 | |||
22 | parent::__construct($name, $title); |
||
23 | } |
||
24 | |||
25 | public function action() { |
||
28 | |||
29 | public function transition() { |
||
32 | |||
33 | public function sort($request) { |
||
34 | if(!SecurityToken::inst()->checkRequest($request)) { |
||
35 | $this->httpError(404); |
||
36 | } |
||
37 | |||
38 | $class = $request->postVar('class'); |
||
39 | $ids = $request->postVar('id'); |
||
40 | |||
41 | if($class == 'WorkflowAction') { |
||
42 | $objects = $this->Definition()->Actions(); |
||
43 | } elseif($class == 'WorkflowTransition') { |
||
44 | $parent = $request->postVar('parent'); |
||
45 | $action = $this->Definition()->Actions()->byID($parent); |
||
46 | |||
47 | if(!$action) { |
||
48 | $this->httpError(400, _t('AdvancedWorkflowAdmin.INVALIDPARENTID', 'An invalid parent ID was specified.')); |
||
49 | } |
||
50 | |||
51 | $objects = $action->Transitions(); |
||
52 | } else { |
||
53 | $this->httpError(400, _t('AdvancedWorkflowAdmin.INVALIDCLASSTOORDER', 'An invalid class to order was specified.')); |
||
54 | } |
||
55 | |||
56 | if(array_diff($ids, $objects->column('ID'))) { |
||
57 | $this->httpError(400, _t('AdvancedWorkflowAdmin.INVALIDIDLIST', 'An invalid list of IDs was provided.')); |
||
58 | } |
||
59 | |||
60 | singleton('WorkflowService')->reorder($objects, $ids); |
||
61 | |||
62 | return new SS_HTTPResponse( |
||
63 | null, 200, _t('AdvancedWorkflowAdmin.SORTORDERSAVED', 'The sort order has been saved.') |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | public function getTemplate() { |
||
70 | |||
71 | public function FieldHolder($properties = array()) { |
||
72 | Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); |
||
73 | Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js'); |
||
74 | Requirements::javascript(ADVANCED_WORKFLOW_DIR . '/javascript/WorkflowField.js'); |
||
75 | Requirements::css(ADVANCED_WORKFLOW_DIR . '/css/WorkflowField.css'); |
||
76 | |||
77 | return $this->Field($properties); |
||
78 | } |
||
79 | |||
80 | public function Definition() { |
||
83 | |||
84 | public function ActionLink() { |
||
85 | $parts = func_get_args(); |
||
86 | array_unshift($parts, 'action'); |
||
87 | |||
88 | return $this->Link(implode('/', $parts)); |
||
89 | } |
||
90 | |||
91 | public function TransitionLink() { |
||
92 | $parts = func_get_args(); |
||
93 | array_unshift($parts, 'transition'); |
||
94 | |||
95 | return $this->Link(implode('/', $parts)); |
||
96 | } |
||
97 | |||
98 | public function CreateableActions() { |
||
117 | |||
118 | } |
||
119 |
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.