Use the assets manager.

This commit is contained in:
David Molineus
2016-10-05 16:11:59 +02:00
parent 971f905ad2
commit 3e84260e79
2 changed files with 22 additions and 15 deletions

View File

@@ -56,8 +56,8 @@ $container[LeafletServices::MAP_PROVIDER] = $container->share(function ($contain
/* /*
* Contao assets handler. Loads Leaflet assets as contao (static) assets. * Contao assets handler. Loads Leaflet assets as contao (static) assets.
*/ */
$container[LeafletServices::MAP_ASSETS] = $container->share(function () { $container[LeafletServices::MAP_ASSETS] = $container->share(function ($container) {
return new ContaoAssets(); return new ContaoAssets($container[Services::ASSETS_MANAGER]);
}); });
/* /*

View File

@@ -11,6 +11,7 @@
namespace Netzmacht\Contao\Leaflet; namespace Netzmacht\Contao\Leaflet;
use Netzmacht\Contao\Toolkit\View\Assets\AssetsManager;
use Netzmacht\LeafletPHP\Assets; use Netzmacht\LeafletPHP\Assets;
/** /**
@@ -27,6 +28,23 @@ class ContaoAssets implements Assets
*/ */
private $map; 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} * {@inheritdoc}
* *
@@ -40,14 +58,8 @@ class ContaoAssets implements Assets
break; break;
case static::TYPE_FILE: case static::TYPE_FILE:
if (!\Config::get('debugMode') && TL_MODE === 'FE') {
$script .= '|static';
}
// no break
default: default:
$GLOBALS['TL_JAVASCRIPT'][] = $script; $this->assetsManager->addJavascript($script);
} }
} }
@@ -64,13 +76,8 @@ class ContaoAssets implements Assets
break; break;
case static::TYPE_FILE: case static::TYPE_FILE:
if (!\Config::get('debugMode')) {
$stylesheet .= '|all|static';
}
// no break
default: default:
$GLOBALS['TL_CSS'][] = $stylesheet; $this->assetsManager->addStylesheet($stylesheet);
} }
} }