diff --git a/src/Frontend/MapElement.php b/src/Frontend/ContentElement/MapElement.php similarity index 84% rename from src/Frontend/MapElement.php rename to src/Frontend/ContentElement/MapElement.php index 5e0c46c..72eb6fa 100644 --- a/src/Frontend/MapElement.php +++ b/src/Frontend/ContentElement/MapElement.php @@ -12,7 +12,9 @@ declare(strict_types=1); -namespace Netzmacht\Contao\Leaflet\Frontend; +namespace Netzmacht\Contao\Leaflet\Frontend\ContentElement; + +use Netzmacht\Contao\Leaflet\Frontend\AbstractMapHybrid; /** * The content element for the leaflet map. @@ -36,7 +38,7 @@ class MapElement extends AbstractMapHybrid protected function getIdentifier(): string { if ($this->get('leaflet_mapId')) { - return $this->get('leaflet_mapId'); + return (string) $this->get('leaflet_mapId'); } if ($this->get('cssID')[0]) { diff --git a/src/Frontend/ContentElement/MapElementFactory.php b/src/Frontend/ContentElement/MapElementFactory.php new file mode 100644 index 0000000..30e525d --- /dev/null +++ b/src/Frontend/ContentElement/MapElementFactory.php @@ -0,0 +1,69 @@ + + * @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\Frontend\ContentElement; + +use Netzmacht\Contao\Leaflet\Frontend\ContentElement\MapElement; +use Netzmacht\Contao\Toolkit\Component\Component; +use Netzmacht\Contao\Toolkit\Component\ComponentFactory; +use Psr\Container\ContainerInterface as Container; + +/** + * Class MapElementFactory + * + * @package Netzmacht\Contao\Leaflet\Frontend\ContentElement + */ +class MapElementFactory implements ComponentFactory +{ + /** + * Dependency container. + * + * @var Container + */ + private $container; + + /** + * MapElementFactory constructor. + * + * @param Container $container Dependency container. + */ + public function __construct(Container $container) + { + $this->container = $container; + } + + /** + * {@inheritDoc} + */ + public function supports($model): bool + { + return $model->type === 'leaflet'; + } + + /** + * {@inheritDoc} + */ + public function create($model, string $column): Component + { + return new MapElement( + $model, + $this->container->get('netzmacht.contao_toolkit.view.template_factory'), + $this->container->get('translator'), + $this->container->get('netzmacht.contao_leaflet_maps.map.provider'), + $this->container->get('netzmacht.contao_toolkit.contao.input'), + $this->container->get('netzmacht.contao_toolkit.contao.config'), + $column + ); + } +} diff --git a/src/Frontend/MapModule.php b/src/Frontend/Module/MapModule.php similarity index 84% rename from src/Frontend/MapModule.php rename to src/Frontend/Module/MapModule.php index 8f47ebe..f3239f3 100644 --- a/src/Frontend/MapModule.php +++ b/src/Frontend/Module/MapModule.php @@ -12,7 +12,9 @@ declare(strict_types=1); -namespace Netzmacht\Contao\Leaflet\Frontend; +namespace Netzmacht\Contao\Leaflet\Frontend\Module; + +use Netzmacht\Contao\Leaflet\Frontend\AbstractMapHybrid; /** * The frontend module for the Leaflet map. @@ -36,7 +38,7 @@ class MapModule extends AbstractMapHybrid protected function getIdentifier(): string { if ($this->get('leaflet_mapId')) { - return $this->get('leaflet_mapId'); + return (string) $this->get('leaflet_mapId'); } if ($this->get('cssID')[0]) { diff --git a/src/Frontend/Module/MapModuleFactory.php b/src/Frontend/Module/MapModuleFactory.php new file mode 100644 index 0000000..9622258 --- /dev/null +++ b/src/Frontend/Module/MapModuleFactory.php @@ -0,0 +1,69 @@ + + * @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\Frontend\Module; + +use Netzmacht\Contao\Leaflet\Frontend\Module\MapModule; +use Netzmacht\Contao\Toolkit\Component\Component; +use Netzmacht\Contao\Toolkit\Component\ComponentFactory; +use Psr\Container\ContainerInterface as Container; + +/** + * Class MapElementFactory + * + * @package Netzmacht\Contao\Leaflet\Frontend\ContentElement + */ +class MapModuleFactory implements ComponentFactory +{ + /** + * Dependency container. + * + * @var Container + */ + private $container; + + /** + * MapModuleFactory constructor. + * + * @param Container $container Dependency container. + */ + public function __construct(Container $container) + { + $this->container = $container; + } + + /** + * {@inheritDoc} + */ + public function supports($model): bool + { + return $model->type === 'leaflet'; + } + + /** + * {@inheritDoc} + */ + public function create($model, string $column): Component + { + return new MapModule( + $model, + $this->container->get('netzmacht.contao_toolkit.view.template_factory'), + $this->container->get('translator'), + $this->container->get('netzmacht.contao_leaflet_maps.map.provider'), + $this->container->get('netzmacht.contao_toolkit.contao.input'), + $this->container->get('netzmacht.contao_toolkit.contao.config'), + $column + ); + } +} diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 66f1e17..5527eb4 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -73,3 +73,17 @@ services: class: Netzmacht\Contao\Leaflet\Alias\ParentAliasGeneratorFactory arguments: - '@database_connection' + + netzmacht.contao_leaflet_maps.frontend.element_factory: + class: Netzmacht\Contao\Leaflet\Frontend\ContentElement\MapElementFactory + arguments: + - '@service_container' + tags: + - { name: 'netzmacht.contao_toolkit.component.content_element_factory' } + + netzmacht.contao_leaflet_maps.frontend.module_factory: + class: Netzmacht\Contao\Leaflet\Frontend\Module\MapModuleFactory + arguments: + - '@service_container' + tags: + - { name: 'netzmacht.contao_toolkit.component.frontend_module_factory' }