Skip to content

Commit

Permalink
Added AssetMapper support (#20 #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkounay authored Mar 1, 2024
1 parent 73bf56f commit 32cf3b3
Show file tree
Hide file tree
Showing 25 changed files with 547 additions and 2,223 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
28 changes: 28 additions & 0 deletions DependencyInjection/ArkounayUxMediaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Arkounay\Bundle\UxMediaBundle\DependencyInjection;

use Arkounay\Bundle\UxMediaBundle\Form\UxMediaType;
use Symfony\Component\AssetMapper\AssetMapperInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
Expand All @@ -22,6 +23,18 @@ public function prepend(ContainerBuilder $container): void
}

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

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

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

public function load(array $configs, ContainerBuilder $container): void
Expand All @@ -39,4 +52,19 @@ 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');
}
}
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
# Ux Media

Symfony UX async document upload type using ArtgrisFileManager, a [MediaBundle](https://github.com/artgris/MediaBundle) version that works without having to use most of its dependecies like jQuery / jQuery UI / Font awesome etc (but **still requires bootstrap 5**)
Symfony UX async document upload form type using ArtgrisFileManager, a [MediaBundle](https://github.com/artgris/MediaBundle) version that works without having to use most of its dependecies like jQuery / jQuery UI / Font awesome etc (but **still requires bootstrap 5**)

## Installation

**Before you start, make sure you have [StimulusBundle](https://symfony.com/bundles/StimulusBundle/current/index.html) configured in your app.**

Install the bundle using Composer and Symfony Flex:

```sh
composer require arkounay/ux-media
```

If you're using WebpackEncore, install your assets and restart Encore (not needed if you're using AssetMapper):

# Don't forget to install the JavaScript dependencies as well and compile
```sh
npm install --force
npm run watch

# or use yarn
yarn install --force
yarn encore dev
yarn watch
```

Also make sure you have at least version 3.0 of [@symfony/stimulus-bridge](https://github.com/symfony/stimulus-bridge)
in your `package.json` file.


### Configuration prerequisites

Expand Down Expand Up @@ -130,7 +138,7 @@ public function configureCrud(): Crud
}
```

You will need to configure your admin to use WebpackEncore so Symfony UX is taken into account, for example:
If you're using WebpackEncore, you will need to configure your admin to use it so Symfony UX is taken into account, for example:
```php
public function configureAssets(Assets $assets): Assets
{
Expand Down
4 changes: 0 additions & 4 deletions Resources/assets/.babelrc

This file was deleted.

47 changes: 0 additions & 47 deletions Resources/assets/dist/bootstrap_modal_controller.js

This file was deleted.

190 changes: 0 additions & 190 deletions Resources/assets/dist/crop_controller.js

This file was deleted.

Loading

0 comments on commit 32cf3b3

Please sign in to comment.