Register libraries.

This commit is contained in:
David Molineus
2017-10-06 15:36:04 +02:00
parent a43b740ba0
commit e8edeb8021
2 changed files with 58 additions and 1 deletions

View File

@@ -0,0 +1,56 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2016-2017 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\DependencyInjection\Pass;
use Netzmacht\LeafletPHP\Assets;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Class RegisterLibrariesPass.
*
* @package Netzmacht\Contao\Leaflet\DependencyInjection\Pass
*/
class RegisterLibrariesPass implements CompilerPassInterface
{
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('netzmacht.contao_leaflet_maps.definition.builder')) {
return;
}
if (!$container->hasParameter('netzmacht.contao_leaflet_maps.libraries')) {
return;
}
$definition = $container->getDefinition('netzmacht.contao_leaflet_maps.definition.builder');
$libraries = $container->getParameter('netzmacht.contao_leaflet_maps.libraries');
foreach ($libraries as $name => $assets) {
if (!empty($assets['css'])) {
list ($source, $type) = (array) $assets['css'];
$definition->addMethodCall('registerStylesheet', [$name, $source, $type ?: Assets::TYPE_FILE]);
}
if (!empty($assets['javascript'])) {
list ($source, $type) = (array) $assets['javascript'];
$definition->addMethodCall('registerJavascript', [$name, $source, $type ?: Assets::TYPE_FILE]);
}
}
}
}

View File

@@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet; namespace Netzmacht\Contao\Leaflet;
use Netzmacht\Contao\Leaflet\DependencyInjection\Pass\RegisterLibrariesPass;
use Netzmacht\Contao\Leaflet\DependencyInjection\Pass\RegisterDefinitionMapperPass; use Netzmacht\Contao\Leaflet\DependencyInjection\Pass\RegisterDefinitionMapperPass;
use Netzmacht\Contao\Leaflet\DependencyInjection\Pass\RegisterEncodersPass; use Netzmacht\Contao\Leaflet\DependencyInjection\Pass\RegisterEncodersPass;
use Netzmacht\Contao\Toolkit\DependencyInjection\CompilerPass\AddTaggedServicesAsArgumentCompilerPass; use Netzmacht\Contao\Toolkit\DependencyInjection\CompilerPass\AddTaggedServicesAsArgumentCompilerPass;
@@ -34,7 +35,7 @@ class NetzmachtContaoLeafletBundle extends Bundle
{ {
$container->addCompilerPass(new RegisterDefinitionMapperPass()); $container->addCompilerPass(new RegisterDefinitionMapperPass());
$container->addCompilerPass(new RegisterEncodersPass()); $container->addCompilerPass(new RegisterEncodersPass());
$container->addCompilerPass(new RegisterLibrariesPass());
$container->addCompilerPass( $container->addCompilerPass(
new AddTaggedServicesAsArgumentCompilerPass( new AddTaggedServicesAsArgumentCompilerPass(
'netzmacht.contao_leaflet_maps.layer_label_renderer', 'netzmacht.contao_leaflet_maps.layer_label_renderer',