diff --git a/assets/package.json b/assets/package.json index 1a3b39b5..f638d601 100755 --- a/assets/package.json +++ b/assets/package.json @@ -15,6 +15,10 @@ "fetch": "eager", "enabled": true } + }, + "importmap": { + "@hotwired/stimulus": "^3.0.0", + "sortablejs": "^1.15.0" } }, "peerDependencies": { diff --git a/docs/installation.md b/docs/installation.md index bc7efba2..5788a5b9 100755 --- a/docs/installation.md +++ b/docs/installation.md @@ -62,11 +62,11 @@ Now, add `@kreyu/data-table-bundle` controllers to your `assets/controllers.json ## Install front-end dependencies and rebuild -The build process obviously depends on the configuration of your project. +If you're using WebpackEncore, install your assets and restart Encore (not needed if you're using AssetMapper): +++ yarn ```shell -$ yarn install +$ yarn install --force $ yarn watch ``` +++ npm diff --git a/src/DependencyInjection/KreyuDataTableExtension.php b/src/DependencyInjection/KreyuDataTableExtension.php index 5ddd578a..5b479d27 100755 --- a/src/DependencyInjection/KreyuDataTableExtension.php +++ b/src/DependencyInjection/KreyuDataTableExtension.php @@ -21,6 +21,7 @@ use Kreyu\Bundle\DataTableBundle\Persistence\PersistenceAdapterInterface; use Kreyu\Bundle\DataTableBundle\Query\ProxyQueryFactoryInterface; use Kreyu\Bundle\DataTableBundle\Type\DataTableTypeInterface; +use Symfony\Component\AssetMapper\AssetMapperInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; @@ -91,6 +92,16 @@ public function prepend(ContainerBuilder $container): void ], ]); } + + if ($this->isAssetMapperAvailable($container)) { + $container->prependExtensionConfig('framework', [ + 'asset_mapper' => [ + 'paths' => [ + __DIR__ . '/../../assets/controllers' => '@kreyu/data-table-bundle', + ], + ], + ]); + } } private function resolveConfiguration(array $configs, ContainerBuilder $container): array @@ -116,4 +127,20 @@ private function resolveConfiguration(array $configs, ContainerBuilder $containe return $config; } + + private function isAssetMapperAvailable(ContainerBuilder $container): bool + { + if (!interface_exists(AssetMapperInterface::class)) { + return false; + } + + // check that FrameworkBundle 6.3 or higher is installed + $bundlesMetadata = $container->getParameter('kernel.bundles_metadata'); + + if (!isset($bundlesMetadata['FrameworkBundle'])) { + return false; + } + + return is_file($bundlesMetadata['FrameworkBundle']['path'] . '/Resources/config/asset_mapper.php'); + } }