Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssetMapper Support #43

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}