Skip to content

Commit

Permalink
Improve link and dropdown-related actions documentation by providing …
Browse files Browse the repository at this point in the history
…a description about "callable" options
  • Loading branch information
Kreyu committed Jan 12, 2025
1 parent 2ac1161 commit 4b19800
Showing 4 changed files with 75 additions and 18 deletions.
8 changes: 5 additions & 3 deletions docs/src/docs/components/actions.md
Original file line number Diff line number Diff line change
@@ -585,9 +585,11 @@ $builder
->addRowAction('advanced', DropdownActionType::class, [
'actions' => [
$builder->createRowAction('update', LinkDropdownItemActionType::class, [
'href' => fn (Post $post) => $this->urlGenerator->generate('post_delete', [
'id' => $post->getId(),
]),
'href' => function (Post $post) {
return $this->urlGenerator->generate('post_delete', [
'id' => $post->getId(),
]),
},
]),
],
])
10 changes: 6 additions & 4 deletions docs/src/reference/types/action.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@

The following action types are natively available in the bundle:

- [Link](#)
- [Button](#)
- [Callback](#)
- [Action](#)
- [Link](action/link.md)
- [Button](action/button.md)
- [Form](action/form.md)
- [Dropdown](action/dropdown.md)
- [LinkDropdownItem](action/link-dropdown-item.md)
- [Action](action/action.md)
35 changes: 28 additions & 7 deletions docs/src/reference/types/action/link-dropdown-item.md
Original file line number Diff line number Diff line change
@@ -24,9 +24,7 @@ $builder
->addAction('advanced', DropdownActionType::class, [
'actions' => [
$builder->createAction('update', LinkDropdownItemActionType::class, [
'href' => fn (Post $post) => $this->urlGenerator->generate('post_update', [
'id' => $post->getId(),
]),
'href' => '#',
]),
],
])
@@ -44,9 +42,11 @@ $builder
->addRowAction('advanced', DropdownActionType::class, [
'actions' => [
$builder->createRowAction('update', LinkDropdownItemActionType::class, [
'href' => fn (Post $post) => $this->urlGenerator->generate('post_update', [
'id' => $post->getId(),
]),
'href' => function (Post $post) {
return $this->urlGenerator->generate('post_update', [
'id' => $post->getId(),
]);
},
]),
],
])
@@ -55,7 +55,7 @@ $builder

### `target`

- **type**: `string` or `callable`
- **type**: `string` or `callable` (if using as a row action)
- **default**: `'_self'`

Sets the value that will be used as an anchor [target attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target).
@@ -76,6 +76,27 @@ $builder
;
```

When using the `LinkActionType` as a [row action](../../../docs/components/actions.md), you can provide a callable
that will receive the row data as an argument and should return a string.

```php
use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\DropdownActionType;
use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\LinkDropdownItemActionType;

$builder
->addAction('advanced', DropdownActionType::class, [
'actions' => [
$builder->createRowAction('wiki', LinkDropdownItemActionType::class, [
'target' => function (Configuration $configuration) {
return $configuration->isExternal() ? '_blank' : '_self';
},
])
],
])

;
```

## Inherited options

<ActionTypeOptions/>
40 changes: 36 additions & 4 deletions docs/src/reference/types/action/link.md
Original file line number Diff line number Diff line change
@@ -10,12 +10,12 @@ The [`LinkActionType`](https://github.com/Kreyu/data-table-bundle/blob/main/src/

### `href`

- **type**: `string` or `callable`
- **type**: `string` or `callable` (if using as a row action)
- **default**: `'#'`

A value used as an action link [href attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href).

```php #
```php
use Kreyu\Bundle\DataTableBundle\Action\Type\LinkActionType;

$builder
@@ -25,14 +25,31 @@ $builder
;
```

When using the `LinkActionType` as a [row action](../../../docs/components/actions.md), you can provide a callable
that will receive the row data as an argument and should return a string.

```php
use Kreyu\Bundle\DataTableBundle\Action\Type\LinkActionType;

$builder
->addAction('back', LinkActionType::class, [
'href' => function (Category $category) {
return $this->urlGenerator->generate('category_index', [
'id' => $category->getId(),
]);
},
])
;
```

### `target`

- **type**: `string` or `callable`
- **type**: `string` or `callable` (if using as a row action)
- **default**: `'_self'`

Sets the value that will be used as an anchor [target attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target).

```php #
```php
use Kreyu\Bundle\DataTableBundle\Action\Type\LinkActionType;

$builder
@@ -42,6 +59,21 @@ $builder
;
```

When using the `LinkActionType` as a [row action](../../../docs/components/actions.md), you can provide a callable
that will receive the row data as an argument and should return a string.

```php
use Kreyu\Bundle\DataTableBundle\Action\Type\LinkActionType;

$builder
->addRowAction('wiki', LinkActionType::class, [
'target' => function (Configuration $configuration) {
return $configuration->shouldOpenNewTab() ? '_blank' : '_self';
},
])
;
```

## Inherited options

<ActionTypeOptions/>

0 comments on commit 4b19800

Please sign in to comment.