1 | <?php |
||
17 | class GridFieldWorkflowRestrictedEditButton implements GridField_ColumnProvider |
||
18 | { |
||
19 | /** |
||
20 | * Add a column |
||
21 | * |
||
22 | * @param type $gridField |
||
23 | * @param array $columns |
||
24 | */ |
||
25 | public function augmentColumns($gridField, &$columns) |
||
31 | |||
32 | /** |
||
33 | * Append a 'disabled' CSS class to GridField rows whose WorkflowInstance records are not viewable/editable |
||
34 | * by the current user. |
||
35 | * |
||
36 | * This is used to visually "grey out" records and it's leveraged in some overriding JavaScript, to maintain |
||
37 | * an ability to click the target object's hyperlink. |
||
38 | * |
||
39 | * @param GridField $gridField |
||
40 | * @param DataObject $record |
||
41 | * @param string $columnName |
||
42 | * @return array |
||
43 | */ |
||
44 | public function getColumnAttributes($gridField, $record, $columnName) |
||
58 | |||
59 | /** |
||
60 | * Add the title |
||
61 | * |
||
62 | * @param GridField $gridField |
||
63 | * @param string $columnName |
||
64 | * @return array |
||
65 | */ |
||
66 | public function getColumnMetadata($gridField, $columnName) |
||
72 | |||
73 | /** |
||
74 | * Which columns are handled by this component |
||
75 | * |
||
76 | * @param type $gridField |
||
77 | * @return type |
||
78 | */ |
||
79 | public function getColumnsHandled($gridField) |
||
83 | |||
84 | /** |
||
85 | * @param GridField $gridField |
||
86 | * @param DataObject $record |
||
87 | * @param string $columnName |
||
88 | * |
||
89 | * @return string - the HTML for the column |
||
90 | */ |
||
91 | public function getColumnContent($gridField, $record, $columnName) |
||
98 | } |
||
99 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.