Skip to content

Commit ba88033

Browse files
add entity to addIf function for action buttons (#25)
1 parent 4d0c3a6 commit ba88033

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class UserTable extends HelloBootstrapTable
191191
'displayName' => 'edit',
192192
'routeName' => 'edit_user',
193193
'classNames' => 'btn btn-xs btn-warning',
194-
'addIf' => function() {
194+
'addIf' => function(User $user) {
195195
// In this callback it is decided if the button will be rendered.
196196
return $this->security->isGranted('ROLE_USER_EDITOR');
197197
}
@@ -521,7 +521,7 @@ All Options of TextColumn
521521
'routeName' => 'edit_user',
522522
// 'classNames' => 'btn btn-xs' (see below for more information)
523523
'additionalClassNames' => 'btn-warning',
524-
'addIf' => function() {
524+
'addIf' => function(User $user) { // you can use your entity in the function
525525
// In this callback it is decided if the button will be rendered.
526526
return $this->security->isGranted('ROLE_ADMIN');
527527
}
@@ -532,15 +532,15 @@ All Options of TextColumn
532532

533533
#### ActionButtons
534534

535-
| Option | Type | Default | Description |
536-
| -------------------- | ------- | ---------------------------- | ------------------------------------------------------------ |
537-
| displayName | string | "" | label of button |
538-
| routeName | string | "" | route name |
539-
| routeParams | array | ["id"] | Array of property value names for the route parameters. By default is `id` set. |
540-
| classNames | string | "" | CSS class names which added directly to the `a` element. Overrides default class names from YAML config. |
541-
| additionalClassNames | string | "" | You can set default class names in YAML config. Then you can add additional class names to the button without override the default config. |
542-
| attr | array | [ ] | Array of any number of attributes formatted as HTML attributes. The array `["title" => "Show"]` is formatted as `title="Show"`. The `href` and `class` attributes are created by the other options and should not be defined here. |
543-
| addIf | Closure | ` function() {return true;}` | In this callback it is decided if the button will be rendered. |
535+
| Option | Type | Default | Description |
536+
| -------------------- | ------- | ----------------------------------- | ------------------------------------------------------------ |
537+
| displayName | string | "" | label of button |
538+
| routeName | string | "" | route name |
539+
| routeParams | array | ["id"] | Array of property value names for the route parameters. By default is `id` set. |
540+
| classNames | string | "" | CSS class names which added directly to the `a` element. Overrides default class names from YAML config. |
541+
| additionalClassNames | string | "" | You can set default class names in YAML config. Then you can add additional class names to the button without override the default config. |
542+
| attr | array | [ ] | Array of any number of attributes formatted as HTML attributes. The array `["title" => "Show"]` is formatted as `title="Show"`. The `href` and `class` attributes are created by the other options and should not be defined here. |
543+
| addIf | Closure | ` function($entity) {return true;}` | In this callback it is decided if the button will be rendered. |
544544

545545
#### YAML Example
546546

src/Columns/ActionColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function buildData($entity)
3434
* @var ActionButton $button
3535
*/
3636
foreach ($this->outputOptions['buttons'] as $button) {
37-
if ($button->getAddIfCallback()()) {
37+
if ($button->getAddIfCallback()($entity)) {
3838
$routeParams = array();
3939
foreach ($button->getRouteParams() as $param) {
4040
$routeParams[$param] = $this->propertyAccessor->getValue($entity, $param);

src/Data/ActionButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function configureOptions(OptionsResolver $resolver)
4848
'routeName' => null,
4949
'routeParams' => array('id'),
5050
'attr' => array(),
51-
'addIf' => function () {
51+
'addIf' => function ($entity) {
5252
return true;
5353
}
5454
));

0 commit comments

Comments
 (0)