Skip to content

Commit

Permalink
AssetMapper Support (#43)
Browse files Browse the repository at this point in the history
* feat: support asset mapper

* docs: support asset mapper
  • Loading branch information
Kreyu authored Oct 23, 2023
1 parent 3609b5f commit 5499273
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"fetch": "eager",
"enabled": true
}
},
"importmap": {
"@hotwired/stimulus": "^3.0.0",
"sortablejs": "^1.15.0"
}
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions src/DependencyInjection/KreyuDataTableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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');
}
}

0 comments on commit 5499273

Please sign in to comment.