Add module factories.

This commit is contained in:
David Molineus
2017-10-06 14:54:58 +02:00
parent bc425ea772
commit 2c88d7aec5
5 changed files with 160 additions and 4 deletions

View File

@@ -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]) {

View File

@@ -0,0 +1,69 @@
<?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\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
);
}
}

View File

@@ -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]) {

View File

@@ -0,0 +1,69 @@
<?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\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
);
}
}

View File

@@ -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' }