From 4f2f2ac4c32691d7cdcfbce0d20b3017213b079b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Tue, 3 Feb 2026 09:16:24 +0100 Subject: [PATCH] =?UTF-8?q?[Docs]=C2=A0Grouping=20actions=20into=20only=20?= =?UTF-8?q?one=20chapter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/SUMMARY.md | 3 +- docs/grid/{custom_action.md => actions.md} | 149 ++++++++++++++++++++- docs/grid/custom_bulk_action.md | 144 -------------------- 3 files changed, 149 insertions(+), 147 deletions(-) rename docs/grid/{custom_action.md => actions.md} (50%) delete mode 100644 docs/grid/custom_bulk_action.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index e7bae680..27f15164 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -54,8 +54,7 @@ * [Installation](grid/installation.md) * [Creating your first grid](grid/your_first_grid.md) * [Fields](grid/fields.md) - * [Creating a custom Action](grid/custom_action.md) - * [Creating a custom Bulk Action](grid/custom_bulk_action.md) + * [Actions](grid/actions.md) * [Filters](grid/filters.md) * [Creating a custom Filter](grid/custom_filter.md) * [Advanced configuration](grid/advanced_configuration.md) diff --git a/docs/grid/custom_action.md b/docs/grid/actions.md similarity index 50% rename from docs/grid/custom_action.md rename to docs/grid/actions.md index 483b551e..dbeef042 100644 --- a/docs/grid/custom_action.md +++ b/docs/grid/actions.md @@ -1,4 +1,6 @@ -# Creating a custom Action +# Actions + +## Creating a custom Action There are certain cases when built-in action types are not enough. @@ -145,3 +147,148 @@ final class AdminSupplierGrid extends AbstractGrid implements ResourceAwareGridI {% endcode %} {% endtab %} {% endtabs %} + +## Creating a custom Bulk Action + +In some cases, forcing the user to click a button for each item in a grid isn't practical. +Fortunately, you can take advantage of built-in bulk actions. However, these may not always be sufficient and might need customization. + +To do this, simply create your own bulk action template and register it inside the `sylius_grid`. + +In the template we will specify the button's icon to be `export` and its +colour to be `orange`. + +{% code title="@App/Grid/BulkAction/export.html.twig" %} +```twig +{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %} + +{% set path = options.link.url|default(path(options.link.route)) %} + +{{ buttons.default(path, action.label, null, 'export', 'orange') }} +``` +{% endcode %} + +Now configure the new action's template: + +{% code title="config/packages/sylius_grid.yaml" lineNumbers="true" %} +```yaml +sylius_grid: + templates: + bulk_action: + export: "@App/Grid/BulkAction/export.html.twig" +``` +{% endcode %} + +From now on, you can use your new bulk action type in the grid configuration! + +Let's assume that you already have a route for exporting by injecting +ids. Now, you can configure the grid action: + +{% tabs %} +{% tab title="YAML" %} +{% code title="config/packages/sylius_grid.yaml" lineNumbers="true" %} +```yaml +sylius_grid: + grids: + app_admin_product: + ... + actions: + bulk: + export: + type: export + label: Export Data + options: + link: + route: app_admin_product_export + parameters: + format: csv +``` +{% endcode %} +{% endtab %} + +{% tab title="PHP" %} +{% code title="config/packages/sylius_grid.php" lineNumbers="true" %} +```php +addGrid(GridBuilder::create('app_admin_product', Product::class) + ->addActionGroup( + BulkActionGroup::create( + Action::create('export', 'export') + ->setLabel('Export Data') + ->setOptions([ + 'link' => [ + 'route' => 'app_admin_product_export', + 'parameters' => [ + 'format' => 'csv', + ], + ] + ]) + ) + ) + ) +}; +``` +{% endcode %} + +OR + +{% code title="src/Grid/AdminProductGrid.php" lineNumbers="true" %} +```php +addActionGroup( + BulkActionGroup::create( + Action::create('export', 'export') + ->setLabel('Export Data') + ->setOptions([ + 'link' => [ + 'route' => 'app_admin_product_export', + 'parameters' => [ + 'format' => 'csv', + ], + ] + ]) + ) + ) + ; + } + + public function getResourceClass(): string + { + return Product::class; + } +} +``` +{% endcode %} +{% endtab %} +{% endtabs %} diff --git a/docs/grid/custom_bulk_action.md b/docs/grid/custom_bulk_action.md deleted file mode 100644 index 7ae47465..00000000 --- a/docs/grid/custom_bulk_action.md +++ /dev/null @@ -1,144 +0,0 @@ -# Creating a custom Bulk Action - -In some cases, forcing the user to click a button for each item in a grid isn't practical. -Fortunately, you can take advantage of built-in bulk actions. However, these may not always be sufficient and might need customization. - -To do this, simply create your own bulk action template and register it inside the `sylius_grid`. - -In the template we will specify the button's icon to be `export` and its -colour to be `orange`. - -{% code title="@App/Grid/BulkAction/export.html.twig" %} -```twig -{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %} - -{% set path = options.link.url|default(path(options.link.route)) %} - -{{ buttons.default(path, action.label, null, 'export', 'orange') }} -``` -{% endcode %} - -Now configure the new action's template: - -{% code title="config/packages/sylius_grid.yaml" lineNumbers="true" %} -```yaml -sylius_grid: - templates: - bulk_action: - export: "@App/Grid/BulkAction/export.html.twig" -``` -{% endcode %} - -From now on, you can use your new bulk action type in the grid configuration! - -Let's assume that you already have a route for exporting by injecting -ids. Now, you can configure the grid action: - -{% tabs %} -{% tab title="YAML" %} -{% code title="config/packages/sylius_grid.yaml" lineNumbers="true" %} -```yaml -sylius_grid: - grids: - app_admin_product: - ... - actions: - bulk: - export: - type: export - label: Export Data - options: - link: - route: app_admin_product_export - parameters: - format: csv -``` -{% endcode %} -{% endtab %} - -{% tab title="PHP" %} -{% code title="config/packages/sylius_grid.php" lineNumbers="true" %} -```php -addGrid(GridBuilder::create('app_admin_product', Product::class) - ->addActionGroup( - BulkActionGroup::create( - Action::create('export', 'export') - ->setLabel('Export Data') - ->setOptions([ - 'link' => [ - 'route' => 'app_admin_product_export', - 'parameters' => [ - 'format' => 'csv', - ], - ] - ]) - ) - ) - ) -}; -``` -{% endcode %} - -OR - -{% code title="src/Grid/AdminProductGrid.php" lineNumbers="true" %} -```php -addActionGroup( - BulkActionGroup::create( - Action::create('export', 'export') - ->setLabel('Export Data') - ->setOptions([ - 'link' => [ - 'route' => 'app_admin_product_export', - 'parameters' => [ - 'format' => 'csv', - ], - ] - ]) - ) - ) - ; - } - - public function getResourceClass(): string - { - return Product::class; - } -} -``` -{% endcode %} -{% endtab %} -{% endtabs %}