From daf902b989186ea7bac4a44ca8a729a7ce3a3173 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Thu, 6 Oct 2016 09:02:12 +0200 Subject: [PATCH] Use assets manager in the marker cluster layer mapper. --- module/config/config.php | 6 ++++- .../Mapper/Layer/MarkerClusterLayerMapper.php | 23 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/module/config/config.php b/module/config/config.php index 3f3d6fc..cf03d4d 100644 --- a/module/config/config.php +++ b/module/config/config.php @@ -93,7 +93,11 @@ $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\MarkersLa $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\GroupLayerMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\VectorsLayerMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\ReferenceLayerMapper'; -$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\MarkerClusterLayerMapper'; +$GLOBALS['LEAFLET_MAPPERS'][] = function () { + return new \Netzmacht\Contao\Leaflet\Mapper\Layer\MarkerClusterLayerMapper( + $GLOBALS['container'][\Netzmacht\Contao\Toolkit\DependencyInjection\Services::ASSETS_MANAGER] + ); +}; // Control mappers. $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\ZoomControlMapper'; diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkerClusterLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkerClusterLayerMapper.php index 2024c81..1cc3167 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkerClusterLayerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkerClusterLayerMapper.php @@ -14,6 +14,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer; use Netzmacht\Contao\Leaflet\Filter\Filter; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\LayerModel; +use Netzmacht\Contao\Toolkit\View\Assets\AssetsManager; use Netzmacht\JavascriptBuilder\Type\AnonymousFunction; use Netzmacht\JavascriptBuilder\Type\Expression; use Netzmacht\LeafletPHP\Definition; @@ -42,6 +43,25 @@ class MarkerClusterLayerMapper extends AbstractLayerMapper */ protected static $type = 'markercluster'; + /** + * Assets manager. + * + * @var AssetsManager + */ + private $assetsManager; + + /** + * MarkerClusterLayerMapper constructor. + * + * @param AssetsManager $assetsManager Assets manager. + */ + public function __construct(AssetsManager $assetsManager) + { + parent::__construct(); + + $this->assetsManager = $assetsManager; + } + /** * {@inheritdoc} */ @@ -61,7 +81,6 @@ class MarkerClusterLayerMapper extends AbstractLayerMapper /** * {@inheritdoc} - * @SuppressWarnings(PHPMD.Superglobals) */ protected function build( Definition $definition, @@ -83,7 +102,7 @@ class MarkerClusterLayerMapper extends AbstractLayerMapper } if (!$model->disableDefaultStyle) { - $GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet-markercluster/MarkerCluster.Default.css||static'; + $this->assetsManager->addStylesheet('assets/leaflet/libs/leaflet-markercluster/MarkerCluster.Default.css'); } $collection = LayerModel::findBy(