1 | <?php |
||
34 | class ActionColumn extends Column |
||
35 | { |
||
36 | /** |
||
37 | * @inheritdoc |
||
38 | */ |
||
39 | public $headerOptions = ['class' => 'action-column']; |
||
40 | /** |
||
41 | * @var string the ID of the controller that should handle the actions specified here. |
||
42 | * If not set, it will use the currently active controller. This property is mainly used by |
||
43 | * [[urlCreator]] to create URLs for different actions. The value of this property will be prefixed |
||
44 | * to each action name to form the route of the action. |
||
45 | */ |
||
46 | public $controller; |
||
47 | /** |
||
48 | * @var string the template used for composing each cell in the action column. |
||
49 | * Tokens enclosed within curly brackets are treated as controller action IDs (also called *button names* |
||
50 | * in the context of action column). They will be replaced by the corresponding button rendering callbacks |
||
51 | * specified in [[buttons]]. For example, the token `{view}` will be replaced by the result of |
||
52 | * the callback `buttons['view']`. If a callback cannot be found, the token will be replaced with an empty string. |
||
53 | * |
||
54 | * As an example, to only have the view, and update button you can add the ActionColumn to your GridView columns as follows: |
||
55 | * |
||
56 | * ```php |
||
57 | * ['class' => 'yii\grid\ActionColumn', 'template' => '{view} {update}'], |
||
58 | * ``` |
||
59 | * |
||
60 | * @see buttons |
||
61 | */ |
||
62 | public $template = '{view} {update} {delete}'; |
||
63 | /** |
||
64 | * @var array button rendering callbacks. The array keys are the button names (without curly brackets), |
||
65 | * and the values are the corresponding button rendering callbacks. The callbacks should use the following |
||
66 | * signature: |
||
67 | * |
||
68 | * ```php |
||
69 | * function ($url, $model, $key) { |
||
70 | * // return the button HTML code |
||
71 | * } |
||
72 | * ``` |
||
73 | * |
||
74 | * where `$url` is the URL that the column creates for the button, `$model` is the model object |
||
75 | * being rendered for the current row, and `$key` is the key of the model in the data provider array. |
||
76 | * |
||
77 | * You can add further conditions to the button, for example only display it, when the model is |
||
78 | * editable (here assuming you have a status field that indicates that): |
||
79 | * |
||
80 | * ```php |
||
81 | * [ |
||
82 | * 'update' => function ($url, $model, $key) { |
||
83 | * return $model->status === 'editable' ? Html::a('Update', $url) : ''; |
||
84 | * }, |
||
85 | * ], |
||
86 | * ``` |
||
87 | */ |
||
88 | public $buttons = []; |
||
89 | /** @var array visibility conditions for each button. The array keys are the button names (without curly brackets), |
||
90 | * and the values are the boolean true/false or the anonymous function. When the button name is not specified in |
||
91 | * this array it will be shown by default. |
||
92 | * The callbacks must use the following signature: |
||
93 | * |
||
94 | * ```php |
||
95 | * function ($model, $key, $index) { |
||
96 | * return $model->status === 'editable'; |
||
97 | * } |
||
98 | * ``` |
||
99 | * |
||
100 | * Or you can pass a boolean value: |
||
101 | * |
||
102 | * ```php |
||
103 | * [ |
||
104 | * 'update' => \Yii::$app->user->can('update'), |
||
105 | * ], |
||
106 | * ``` |
||
107 | * @since 2.0.7 |
||
108 | */ |
||
109 | public $visibleButtons = []; |
||
110 | /** |
||
111 | * @var callable a callback that creates a button URL using the specified model information. |
||
112 | * The signature of the callback should be the same as that of [[createUrl()]] |
||
113 | * Since 2.0.10 it can accept additional parameter, which refers to the column instance itself: |
||
114 | * |
||
115 | * ```php |
||
116 | * function (string $action, mixed $model, mixed $key, integer $index, ActionColumn $this) { |
||
117 | * //return string; |
||
118 | * } |
||
119 | * ``` |
||
120 | * |
||
121 | * If this property is not set, button URLs will be created using [[createUrl()]]. |
||
122 | */ |
||
123 | public $urlCreator; |
||
124 | /** |
||
125 | * @var array html options to be applied to the [[initDefaultButton()|default button]]. |
||
126 | * @since 2.0.4 |
||
127 | */ |
||
128 | public $buttonOptions = []; |
||
129 | |||
130 | |||
131 | /** |
||
132 | * @inheritdoc |
||
133 | */ |
||
134 | public function init() |
||
139 | |||
140 | /** |
||
141 | * Initializes the default button rendering callbacks. |
||
142 | */ |
||
143 | protected function initDefaultButtons() |
||
152 | |||
153 | /** |
||
154 | * Initializes the default button rendering callback for single button |
||
155 | * @param string $name Button name as it's written in template |
||
156 | * @param string $iconName The part of Bootstrap glyphicon class that makes it unique |
||
157 | * @param array $additionalOptions Array of additional options |
||
158 | * @since 2.0.11 |
||
159 | */ |
||
160 | protected function initDefaultButton($name, $iconName, $additionalOptions = []) |
||
187 | |||
188 | /** |
||
189 | * Creates a URL for the given action and model. |
||
190 | * This method is called for each button and each row. |
||
191 | * @param string $action the button name (or action ID) |
||
192 | * @param \yii\db\ActiveRecord $model the data model |
||
193 | * @param mixed $key the key associated with the data model |
||
194 | * @param int $index the current row index |
||
195 | * @return string the created URL |
||
196 | */ |
||
197 | public function createUrl($action, $model, $key, $index) |
||
208 | |||
209 | /** |
||
210 | * @inheritdoc |
||
211 | */ |
||
212 | protected function renderDataCellContent($model, $key, $index) |
||
233 | } |
||
234 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.