Closed rrr63 closed 1 month ago
Hey @rrr63, the conversion from camel case to sentence only happens if you haven't given a label.
The first argument of the addRowAction
represents the name of the action (e.g. create
, update
, showDetails
), similar to the Symfony Forms, where first argument of the add()
method represents name of the field, not its label. Only if the label
(docs) option is not given, the name gets converted to sentence case as a fallback (e.g. showDetails
name fallbacks the label to Show details
).
In your case, you most likely want something like:
$builder
->addAction('create', ButtonActionType::class, [
'label' => 'Create a new Product',
'href' => $this->router->generate('app_product_new'),
])
->addRowAction('edit', ButtonActionType::class, [
'label' => 'Editing a Product',
'href' => function (Product $product) {
return $this->router->generate('app_product_edit', ['id' => $product->getId()]);
},
])
->addRowAction('delete', ButtonActionType::class, [
'label' => 'Deleting a Product',
'confirmation' => true,
'href' => function (Product $product) {
return $this->router->generate('app_product_delete', ['id' => $product->getId()]);
},
])
;
or skip the label
option and use translation to handle the labels (you can set translation domain in configureOptions
like in forms):
// in your data table type class
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefault('translation_domain', 'product');
}
# translations/product.en.yaml
create: Create a new Product
edit: Editing a Product
delete: Deleting a Product
The similar configuration works for other components - columns, filters and exporters.
Hey @rrr63, the conversion from camel case to sentence only happens if you haven't given a label.
The first argument of the
addRowAction
represents the name of the action (e.g.create
,update
,showDetails
), similar to the Symfony Forms, where first argument of theadd()
method represents name of the field, not its label. Only if thelabel
(docs) option is not given, the name gets converted to sentence case as a fallback (e.g.showDetails
name fallbacks the label toShow details
).In your case, you most likely want something like:
$builder ->addAction('create', ButtonActionType::class, [ 'label' => 'Create a new Product', 'href' => $this->router->generate('app_product_new'), ]) ->addRowAction('edit', ButtonActionType::class, [ 'label' => 'Editing a Product', 'href' => function (Product $product) { return $this->router->generate('app_product_edit', ['id' => $product->getId()]); }, ]) ->addRowAction('delete', ButtonActionType::class, [ 'label' => 'Deleting a Product', 'confirmation' => true, 'href' => function (Product $product) { return $this->router->generate('app_product_delete', ['id' => $product->getId()]); }, ]) ;
or skip the
label
option and use translation to handle the labels (you can set translation domain inconfigureOptions
like in forms):// in your data table type class public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefault('translation_domain', 'product'); }
# translations/product.en.yaml create: Create a new Product edit: Editing a Product delete: Deleting a Product
The similar configuration works for other components - columns, filters and exporters.
Thanks ! It was that exactly 👍
Hello,
First, thanks for your bundle, it is amazing work ! I am testing it and it looks very good. I tried to create some rows action with customs labels :
But when i wanted to render it :
it looks like it is always calling the camelToSentence function, but for label maybe we could let user select their own text ?
With this very small PR :