Skip to content

Commit b396e00

Browse files
fix LinkColumn (#27)
1 parent 9ea76b6 commit b396e00

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,9 @@ All Options of TextColumn.
431431

432432
| Option | Type | Default | Description |
433433
| ----------- | ------ | ------- | ------------------------------------------------------------ |
434-
| routeName | string | null | route name. This option is required. |
435-
| routeParams | array | ["id"] | Array of property value names for the route parameters. By default is `id` set. |
436-
| attr | array | [ ] | Array of any number of attributes formatted as HTML attributes. The array `["class" => "btn btn-success"]` is formatted as `title="btn btn-success"`. |
434+
| routeName | string | null | Route name. This option is required. |
435+
| routeParams | array | [] | Array of route parameters. The key is the parameter of the route. The value is the property path. |
436+
| attr | array | [ ] | Array of any number of attributes formatted as HTML attributes. The array `["class" => "btn btn-success"]` is formatted as `class="btn btn-success"`. |
437437

438438
#### Example
439439

@@ -442,10 +442,32 @@ use HelloSebastian\HelloBootstrapTableBundle\Columns\LinkColumn;
442442

443443
->add('department.name', LinkColumn::class, array(
444444
'title' => 'Department',
445-
'routeName' => 'show_department' // this option is required
445+
'routeName' => 'show_department', // this option is required
446+
'routeParams' => array(
447+
'id' => 'department.id' // "id" is the route parameter of "show_department". "department.id" is the property path to fetch the value for the route parameter.
448+
)
446449
))
447450
```
448451

452+
If the route parameters cannot be determined automatically based on the entity, user-defined routes can be created by overwriting `data`. Once `data` is overwritten, `routeName` and `routeParams` are no longer necessary to specify.
453+
454+
```php
455+
use HelloSebastian\HelloBootstrapTableBundle\Columns\LinkColumn;
456+
457+
->add('department.name', LinkColumn::class, array(
458+
'title' => 'Department',
459+
'data' => function (User $user) {
460+
return array(
461+
'displayName' => $user->getDepartment()->getName(),
462+
'route' => $this->router->generate('show_department', array('some_parameter' => 'Hello'),
463+
'attr' => ''
464+
);
465+
}
466+
))
467+
```
468+
469+
470+
449471
---
450472

451473
### CountColumn
@@ -1072,4 +1094,4 @@ class UserTable extends HelloBootstrapTable
10721094

10731095
## Contributing
10741096

1075-
Contributions are **welcome** and will be credited.
1097+
Contributions are **welcome** and will be credited.

src/Columns/LinkColumn.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected function configureOutputOptions(OptionsResolver $resolver)
1414

1515
$resolver->setDefaults(array(
1616
"routeName" => null,
17-
"routeParams" => array("id"),
17+
"routeParams" => array(),
1818
"attr" => array(),
1919
"formatter" => "defaultLinkFormatter"
2020
));
@@ -33,8 +33,8 @@ public function buildData($entity)
3333
}
3434

3535
$routeParams = array();
36-
foreach ($this->outputOptions['routeParams'] as $param) {
37-
$routeParams[$param] = $this->propertyAccessor->getValue($entity, $param);
36+
foreach ($this->outputOptions['routeParams'] as $routeParam => $paramPath) {
37+
$routeParams[$routeParam] = $this->propertyAccessor->getValue($entity, $paramPath);
3838
}
3939

4040
return array(

0 commit comments

Comments
 (0)