1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package advancedworkflow |
5
|
|
|
*/ |
6
|
|
|
class GridFieldWorkflowRestrictedEditButton implements GridField_ColumnProvider { |
|
|
|
|
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Add a column |
10
|
|
|
* |
11
|
|
|
* @param type $gridField |
12
|
|
|
* @param array $columns |
13
|
|
|
*/ |
14
|
|
|
public function augmentColumns($gridField, &$columns) { |
15
|
|
|
if(!in_array('Actions', $columns)) |
16
|
|
|
$columns[] = 'Actions'; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Append a 'disabled' CSS class to GridField rows whose WorkflowInstance records are not viewable/editable |
21
|
|
|
* by the current user. |
22
|
|
|
* |
23
|
|
|
* This is used to visually "grey out" records and it's leveraged in some overriding JavaScript, to maintain an ability |
24
|
|
|
* to click the target object's hyperlink. |
25
|
|
|
* |
26
|
|
|
* @param GridField $gridField |
27
|
|
|
* @param DataObject $record |
28
|
|
|
* @param string $columnName |
29
|
|
|
* @return array |
30
|
|
|
*/ |
31
|
|
|
public function getColumnAttributes($gridField, $record, $columnName) { |
32
|
|
|
$defaultAtts = array('class' => 'col-buttons'); |
33
|
|
|
if($record instanceof WorkflowInstance) { |
34
|
|
|
$isAdmin = Permission::check('ADMIN'); |
35
|
|
|
$isAssigned = $record->getAssignedMembers()->find('ID', Member::currentUserID()); |
36
|
|
|
if(!$isAdmin && !$isAssigned) { |
37
|
|
|
$atts['class'] = $defaultAtts['class'].' disabled'; |
|
|
|
|
38
|
|
|
return $atts; |
39
|
|
|
} |
40
|
|
|
return $defaultAtts; |
41
|
|
|
} |
42
|
|
|
return $defaultAtts; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Add the title |
47
|
|
|
* |
48
|
|
|
* @param GridField $gridField |
49
|
|
|
* @param string $columnName |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public function getColumnMetadata($gridField, $columnName) { |
53
|
|
|
if($columnName == 'Actions') { |
54
|
|
|
return array('title' => ''); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Which columns are handled by this component |
60
|
|
|
* |
61
|
|
|
* @param type $gridField |
62
|
|
|
* @return type |
63
|
|
|
*/ |
64
|
|
|
public function getColumnsHandled($gridField) { |
65
|
|
|
return array('Actions'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param GridField $gridField |
70
|
|
|
* @param DataObject $record |
71
|
|
|
* @param string $columnName |
72
|
|
|
* |
73
|
|
|
* @return string - the HTML for the column |
74
|
|
|
*/ |
75
|
|
|
public function getColumnContent($gridField, $record, $columnName) { |
76
|
|
|
$data = new ArrayData(array( |
77
|
|
|
'Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit') |
78
|
|
|
)); |
79
|
|
|
return $data->renderWith('GridFieldEditButton'); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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.