diff --git a/module/config/services.php b/module/config/services.php index b33168a..3a29c6c 100644 --- a/module/config/services.php +++ b/module/config/services.php @@ -56,8 +56,8 @@ $container[LeafletServices::MAP_PROVIDER] = $container->share(function ($contain /* * Contao assets handler. Loads Leaflet assets as contao (static) assets. */ -$container[LeafletServices::MAP_ASSETS] = $container->share(function () { - return new ContaoAssets(); +$container[LeafletServices::MAP_ASSETS] = $container->share(function ($container) { + return new ContaoAssets($container[Services::ASSETS_MANAGER]); }); /* diff --git a/src/Netzmacht/Contao/Leaflet/ContaoAssets.php b/src/Netzmacht/Contao/Leaflet/ContaoAssets.php index bb46e29..f9bdd72 100644 --- a/src/Netzmacht/Contao/Leaflet/ContaoAssets.php +++ b/src/Netzmacht/Contao/Leaflet/ContaoAssets.php @@ -11,6 +11,7 @@ namespace Netzmacht\Contao\Leaflet; +use Netzmacht\Contao\Toolkit\View\Assets\AssetsManager; use Netzmacht\LeafletPHP\Assets; /** @@ -27,6 +28,23 @@ class ContaoAssets implements Assets */ private $map; + /** + * Assets manager. + * + * @var AssetsManager + */ + private $assetsManager; + + /** + * ContaoAssets constructor. + * + * @param AssetsManager $assetsManager Contao assets manager. + */ + public function __construct(AssetsManager $assetsManager) + { + $this->assetsManager = $assetsManager; + } + /** * {@inheritdoc} * @@ -40,14 +58,8 @@ class ContaoAssets implements Assets break; case static::TYPE_FILE: - if (!\Config::get('debugMode') && TL_MODE === 'FE') { - $script .= '|static'; - } - - // no break - default: - $GLOBALS['TL_JAVASCRIPT'][] = $script; + $this->assetsManager->addJavascript($script); } } @@ -64,13 +76,8 @@ class ContaoAssets implements Assets break; case static::TYPE_FILE: - if (!\Config::get('debugMode')) { - $stylesheet .= '|all|static'; - } - // no break - default: - $GLOBALS['TL_CSS'][] = $stylesheet; + $this->assetsManager->addStylesheet($stylesheet); } }