ModalActionType
The ModalActionType
represents an action that opens a modal dialog with contents loaded from given URL.
WARNING
This action type requires additional JavaScript to work properly. If using the built-in Bootstrap 5 or Tabler (based on Bootstrap) theme, enable the bootstrap-modal
script in your controllers.json
file, because it is disabled by default.
{
"controllers": {
"@kreyu/data-table-bundle": {
"bootstrap-modal": {
"enabled": true
}
}
}
}
Options
href
- type:
null
,string
orcallable
(if using as a row action) - default:
null
A URL to load the modal contents from. Can be used instead of route
and route_params
options, so in most cases this would require to inject the URL generator service:
use Kreyu\Bundle\DataTableBundle\Action\Type\ModalActionType;
$builder
->addAction('help', ModalActionType::class, [
'href' => $this->urlGenerator->generate('post_help_modal');
])
;
When using the ModalActionType
as a row action, you can provide a callable that will receive the row data as an argument and should return a URL.
use Kreyu\Bundle\DataTableBundle\Action\Type\ModalActionType;
$builder
->addRowAction('details', ModalActionType::class, [
'href' => fn (Post $post) => [
$this->urlGenerator->generate('post_details_modal', [
'id' => $post->getId(),
]),
],
])
;
TIP
You can use route
and route_params
options instead of manually injecting the URL generator service. Setting both the href
and route
options simultaneously will use the URL provided in the href
option.
route
- type:
null
,string
orcallable
(if using as a row action) - default:
null
A route name to generate the URL from. Can be used instead of href
option.
use Kreyu\Bundle\DataTableBundle\Action\Type\ModalActionType;
$builder
->addAction('help', ModalActionType::class, [
'route' => 'post_help_modal',
])
;
When using the ModalActionType
as a row action, you can provide a callable that will receive the row data as an argument and should return a route name.
use Kreyu\Bundle\DataTableBundle\Action\Type\ModalActionType;
$builder
->addRowAction('details', ModalActionType::class, [
'route' => fn (Post $post) => $post->isPublished()
? 'post_published_details_modal'
: 'post_draft_details_modal',
])
;
route_params
- type:
array
orcallable
(if using as a row action) - default:
[]
A route params passed to the route provided in route
option. Can be used instead of href
option.
use Kreyu\Bundle\DataTableBundle\Action\Type\ModalActionType;
$builder
->addAction('help', ModalActionType::class, [
'route' => 'post_help_modal',
'route_params' => [
'foo' => 'bar',
],
])
;
When using the ModalActionType
as a row action, you can provide a callable that will receive the row data as an argument and should return a route params array.
use Kreyu\Bundle\DataTableBundle\Action\Type\ModalActionType;
$builder
->addRowAction('details', ModalActionType::class, [
'route' => 'post_details_modal',
'route_params' => fn (Post $post) => [
'id' => $post->getId(),
],
])
;
Inherited options
label
- type:
null
,string
orSymfony\Component\Translation\TranslatableInterface
- default:
null
A label representing the action. When value equals null
, a sentence cased action name is used as a label, for example:
Action name | Guessed label |
---|---|
create | Create |
saveAndClose | Save and close |
label_translation_parameters
- type:
array
- default:
[]
An array of parameters used to translate the action label.
translation_domain
- type:
false
orstring
- default:
'KreyuDataTable'
Translation domain used in translation of action's translatable values.
block_prefix
- type:
string
- default: value returned by the action type
getBlockPrefix()
method
Allows you to add a custom block prefix and override the block name used to render the action type. Useful, for example, if you have multiple instances of the same action type, and you need to personalize the rendering of some of them, without the need to create a new action type.
visible
- type:
bool
orcallable
- default:
true
Determines whether the action should be visible to the user.
The callable can only be used by the row actions to determine visibility based on the row data:
use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType;
$builder
->addRowAction('remove', ButtonActionType::class, [
'visible' => function (Product $product) {
return $product->isRemovable();
},
])
;
attr
- type:
array
- default:
[]
An array of attributes used to render the action.
use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType;
$builder
->addAction('remove', ButtonActionType::class, [
'attr' => [
'class' => 'bg-danger',
],
])
;
icon
- type:
null
,string
orcallable
- default:
null
Defines the icon to render.
use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType;
$builder
->addAction('remove', ButtonActionType::class, [
'icon' => 'trash',
])
;
Wondering how does the icon gets rendered?
Name of the icon depends on the icon set you are using in the application, and which icon theme is configured for the data table. See the icon themes documentation section for more information.
When action is a row action, you can provide a callable that will receive the row data as an argument and should return a string:
use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType;
$builder
->addRowAction('toggle', ButtonActionType::class, [
'icon' => fn (User $user) => $user->isActive() ? 'unlock' : 'lock',
])
;
icon_attr
- type:
array
orcallable
- default:
[]
Defines the HTML attributes for the icon to render.
use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType;
$builder
->addRowAction('status', ButtonActionType::class, [
'icon' => 'check',
'icon_attr' => [
'class' => 'text-success',
],
])
;
When action is a row action, you can provide a callable that will receive the row data as an argument and should return a string:
use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType;
$builder
->addRowAction('toggle', ButtonActionType::class, [
'icon' => fn (User $user) => $user->isActive() ? 'unlock' : 'lock',
'icon_attr' => fn (User $user) => [
'class' => $user->isActive() ? 'text-danger' : 'text-success',
],
])
;
confirmation
- type:
bool
,array
orcallable
- default:
false
Determines whether the action is confirmable, which displays a modal where user have to acknowledge the process. The modal can be configured by passing an array with the following options:
translation_domain
- type:
false
orstring
- default:
'KreyuDataTable'
label_title
- type:
null
orstring
- default:
'Action confirmation'
label_description
- type:
null
orstring
- default:
'Are you sure you want to execute this action?'
label_confirm
- type:
null
orstring
- default:
'Confirm'
label_cancel
- type:
null
orstring
- default:
'Cancel'
type
- type:
null
orstring
- default:
danger
- allowed values:
danger
,warning
,info
Represents a type of the action confirmation, which determines the color of the displayed modal.