Skip to content

v0.32.0

Pre-release
Pre-release

Choose a tag to compare

@Kreyu Kreyu released this 22 Aug 07:24
· 6 commits to main since this release

What's Changed

  • Fix some default filters are not included in URL query params by @maciazek in #228
  • Improve integration with Turbo to allow returning a single frame from controller by @alexandre-castelain in #235
  • Fix profiler page when pagination is disabled by @Kreyu in #237
  • Use closures instead of callables in action options by @Kreyu
  • Improve Bootstrap 5 & Tabler themes to use "data_table_theme_block" function and "attributes" macro for better theming by @Kreyu
  • Allow overriding attributes of action_filter, action_export and action_personalize blocks in Tabler theme by @Kreyu

Closures instead of callables in action options

Previously, all built-in action types had options that accepted callable values. This created an unexpected behavior when provided with a string that is callable. For example, take a look at this simple definition:

$builder->addRowAction('download', ButtonActionType::class, [
    'icon' => 'file',
]);

The provided string "file" is a callable - and it calls the PHP's file function, which would throw an exception:

file(): Argument #1 ($filename) must be of type string, <Some\Example\Entity> given

Now, all built-in actions require passing a \Closure instead of callable when necessary.

Warning

While this is a breaking change, it will break only if you relied on this unexpected behavior, or if you've used invokable classes for those options. Use closures when necessary.

Improved integration with Turbo

The new improved integration with Turbo allows to return a single data table from the controller, making it a perfect fit for pages with multiple data tables. For example:

use Kreyu\Bundle\DataTableBundle\DataTableFactoryAwareTrait;
use Kreyu\Bundle\DataTableBundle\DataTableTurboResponseTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class ProductController extends AbstractController
{
    use DataTableFactoryAwareTrait;
    use DataTableTurboResponseTrait;

    public function index(ProductRepository $productRepository, Request $request): Response
    {
        $query = $productRepository->createQueryBuilder('product');

        $dataTable = $this->createDataTable(ProductDataTableType::class, $query);
        $dataTable->handleRequest($request);

        if ($dataTable->isRequestFromTurboFrame()) {
            // Return only the table's HTML so Turbo can replace the requesting <turbo-frame>
            return $this->createDataTableTurboResponse($dataTable);
        }

        // Rest of the controller logic we don't want to execute each time user interacts with the data table

        // Initial (non-Turbo) request: render the full page
        return $this->render('home/index.html.twig', [
            'products' => $dataTable->createView(),
        ]);
    }
}

You can read more about this feature in https://data-table-bundle.swroblewski.pl/docs/features/asynchronicity.html#server-side-responses-for-turbo-frames

Full Changelog: v0.31.2...v0.32.0