Skip to content

Commit

Permalink
Added support for AssetMapper - ref Arkounay/ux-media#20
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkounay authored Mar 1, 2024
1 parent ae8f289 commit 5ece819
Show file tree
Hide file tree
Showing 15 changed files with 510 additions and 2,202 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
.phpunit.result.cache
.php_cs.cache
composer.lock
Resources/assets/node_modules
assets/node_modules
31 changes: 30 additions & 1 deletion DependencyInjection/ArkounayUxCollectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Arkounay\Bundle\UxCollectionBundle\DependencyInjection;

use Arkounay\Bundle\UxCollectionBundle\Form\UxCollectionType;
use Symfony\Component\AssetMapper\AssetMapperInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class ArkounayUxCollectionExtension extends Extension implements PrependExtensionInterface
{
Expand All @@ -20,6 +21,18 @@ public function prepend(ContainerBuilder $container): void
}

$container->prependExtensionConfig('twig', ['form_themes' => ['@ArkounayUxCollection/ux_collection_form_theme.html.twig']]);

if (!$this->isAssetMapperAvailable($container)) {
return;
}

$container->prependExtensionConfig('framework', [
'asset_mapper' => [
'paths' => [
__DIR__ . '/../assets' => '@arkounay/ux-collection',
],
],
]);
}

public function load(array $configs, ContainerBuilder $container): void
Expand All @@ -30,4 +43,20 @@ public function load(array $configs, ContainerBuilder $container): void
->setPublic(false)
;
}

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');
}

}
4 changes: 0 additions & 4 deletions Resources/assets/.babelrc

This file was deleted.

Loading

0 comments on commit 5ece819

Please sign in to comment.