diff --git a/module/config/autoload.ini b/module/config/autoload.ini
new file mode 100644
index 0000000..2524a49
--- /dev/null
+++ b/module/config/autoload.ini
@@ -0,0 +1 @@
+requires[] = 'toolkit'
diff --git a/module/config/config.php b/module/config/config.php
index adda96d..1d3a8ee 100644
--- a/module/config/config.php
+++ b/module/config/config.php
@@ -56,13 +56,13 @@ array_insert(
/*
* Content elements.
*/
-$GLOBALS['TL_CTE']['includes']['leaflet'] = 'Netzmacht\Contao\Leaflet\Frontend\MapElement';
+$GLOBALS['TL_CTE']['includes']['leaflet'] = 'Netzmacht\Contao\Toolkit\Component\ContentElement\ContentElementDecorator';
/*
* Frontend modules
*/
-$GLOBALS['FE_MOD']['includes']['leaflet'] = 'Netzmacht\Contao\Leaflet\Frontend\MapModule';
+$GLOBALS['FE_MOD']['includes']['leaflet'] = 'Netzmacht\Contao\Toolkit\Component\Module\ModuleDecorator';
/*
diff --git a/module/config/services.php b/module/config/services.php
index f732369..95de655 100644
--- a/module/config/services.php
+++ b/module/config/services.php
@@ -9,9 +9,12 @@
*
*/
+use Interop\Container\ContainerInterface;
use Netzmacht\Contao\Leaflet\Alias\UnderscoreFilter;
use Netzmacht\Contao\Leaflet\Boot;
use Netzmacht\Contao\Leaflet\ContaoAssets;
+use Netzmacht\Contao\Leaflet\Frontend\MapElement;
+use Netzmacht\Contao\Leaflet\Frontend\MapModule;
use Netzmacht\Contao\Leaflet\Frontend\ValueFilter;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\MapService;
@@ -180,3 +183,27 @@ $container['leaflet.dca.control-callbacks'] = $container->share(
);
}
);
+
+$container[Services::CONTENT_ELEMENTS_MAP]['leaflet'] = function ($model, $column, ContainerInterface $container) {
+ return new MapElement(
+ $model,
+ $container->get(Services::TEMPLATE_FACTORY),
+ $container->get(Services::TRANSLATOR),
+ $container->get('leaflet.map.service'),
+ $container->get(Services::INPUT),
+ $container->get(Services::CONFIG),
+ $column
+ );
+};
+
+$container[Services::MODULES_MAP]['leaflet'] = function ($model, $column, ContainerInterface $container) {
+ return new MapModule(
+ $model,
+ $container->get(Services::TEMPLATE_FACTORY),
+ $container->get(Services::TRANSLATOR),
+ $container->get('leaflet.map.service'),
+ $container->get(Services::INPUT),
+ $container->get(Services::CONFIG),
+ $column
+ );
+};
diff --git a/src/Netzmacht/Contao/Leaflet/Frontend/AbstractMapHybrid.php b/src/Netzmacht/Contao/Leaflet/Frontend/AbstractMapHybrid.php
new file mode 100644
index 0000000..ff6ac90
--- /dev/null
+++ b/src/Netzmacht/Contao/Leaflet/Frontend/AbstractMapHybrid.php
@@ -0,0 +1,146 @@
+
+ * @copyright 2015 netzmacht creative David Molineus
+ * @license LGPL 3.0
+ * @filesource
+ *
+ */
+
+namespace Netzmacht\Contao\Leaflet\Frontend;
+
+use ContaoCommunityAlliance\Translator\TranslatorInterface as Translator;
+use Database\Result;
+use Model\Collection;
+use Netzmacht\Contao\Leaflet\MapService;
+use Netzmacht\Contao\Leaflet\Model\MapModel;
+use Netzmacht\Contao\Toolkit\Component\Hybrid\AbstractHybrid;
+use Netzmacht\Contao\Toolkit\View\Template\TemplateFactory;
+
+/**
+ * Class HybridTrait provides method required by the frontend module and content element the same time.
+ *
+ * @package Netzmacht\Contao\Leaflet\Frontend
+ */
+abstract class AbstractMapHybrid extends AbstractHybrid
+{
+ /**
+ * The map service.
+ *
+ * @var MapService
+ */
+ private $mapService;
+
+ /**
+ * The user input.
+ *
+ * @var \Input
+ */
+ private $input;
+
+ /**
+ * The Contao config.
+ *
+ * @var \Config
+ */
+ private $config;
+
+ /**
+ * HybridTrait constructor.
+ *
+ * @param Result|\Model|Collection $model Component model.
+ * @param TemplateFactory $templateFactory Template factory.
+ * @param Translator $translator Translator.
+ * @param MapService $mapService Map service.
+ * @param \Input $input Input
+ * @param \Config $config Config.
+ * @param string $column Column in which the element appears.
+ */
+ public function __construct(
+ $model,
+ TemplateFactory $templateFactory,
+ Translator $translator,
+ MapService $mapService,
+ \Input $input,
+ \Config $config,
+ $column = null
+ ) {
+ parent::__construct($model, $templateFactory, $translator, $column);
+
+ $this->mapService = $mapService;
+ $this->input = $input;
+ $this->config = $config;
+ }
+
+ /**
+ * Do the frontend integration generation.
+ *
+ * @return string
+ */
+ public function generate()
+ {
+ $this->mapService->handleAjaxRequest($this->getIdentifier());
+
+ if (TL_MODE === 'BE') {
+ $model = MapModel::findByPk($this->get('leaflet_map'));
+
+ $template = $this->getTemplateFactory()->createBackendTemplate('be_wildcard');
+
+ if ($model) {
+ $href = 'contao/main.php?do=leaflet&table=tl_leaflet_map&act=edit&id=' . $model->id;
+
+ $template->set('wildcard', '### LEAFLET MAP ' . $model->title . ' ###');
+ $template->set('title', $this->get('headline'));
+ $template->set('id', $model->id);
+ $template->set('link', $model->title);
+ $template->set('href', $href);
+ }
+
+ return $template->parse();
+ }
+
+ return parent::generate();
+ }
+
+ /**
+ * Do the frontend integration compiling.
+ *
+ * @return void
+ *
+ * @throws \Exception If the map could not be created.
+ *
+ * @SuppressWarnings(PHPMD.Superglobals)
+ */
+ protected function compile()
+ {
+ try {
+ $template = $this->get('leaflet_template') ?: 'leaflet_map_js';
+ $mapId = $this->getIdentifier();
+ $map = $this->mapService->generate($this->get('leaflet_map'), null, $mapId, $template);
+
+ $GLOBALS['TL_BODY'][] = '';
+
+ $this->template->set('mapId', $mapId);
+
+ $style = '';
+ $height = deserialize($this->get('leaflet_height'), true);
+ $width = deserialize($this->get('leaflet_width'), true);
+
+ if (!empty($width['value'])) {
+ $style .= 'width:' . $width['value'] . $width['unit'] . ';';
+ }
+
+ if (!empty($height['value'])) {
+ $style .= 'height:' . $height['value'] . $height['unit'] . ';';
+ }
+
+ $this->template->set('mapStyle', $style);
+ } catch (\Exception $e) {
+ throw $e;
+ }
+ }
+
+ abstract protected function getIdentifier();
+}
diff --git a/src/Netzmacht/Contao/Leaflet/Frontend/HybridTrait.php b/src/Netzmacht/Contao/Leaflet/Frontend/HybridTrait.php
deleted file mode 100644
index d163004..0000000
--- a/src/Netzmacht/Contao/Leaflet/Frontend/HybridTrait.php
+++ /dev/null
@@ -1,129 +0,0 @@
-
- * @copyright 2015 netzmacht creative David Molineus
- * @license LGPL 3.0
- * @filesource
- *
- */
-
-namespace Netzmacht\Contao\Leaflet\Frontend;
-
-use Netzmacht\Contao\Leaflet\MapService;
-use Netzmacht\Contao\Leaflet\Model\MapModel;
-
-/**
- * Class HybridTrait provides method required by the frontend module and content element the same time.
- *
- * @package Netzmacht\Contao\Leaflet\Frontend
- */
-trait HybridTrait
-{
- /**
- * The map service.
- *
- * @var MapService
- */
- private $mapService;
-
- /**
- * The user input.
- *
- * @var \Input
- */
- private $input;
-
- /**
- * The Contao config.
- *
- * @var \Config
- */
- private $config;
-
- /**
- * Construct.
- *
- * @param \ContentModel $objElement Content element model.
- * @param string $strColumn Layout column.
- *
- * @return void
- */
- protected function construct($objElement, $strColumn = 'main')
- {
- parent::__construct($objElement, $strColumn);
-
- $this->mapService = static::getService('leaflet.map.service');
- $this->input = static::getService('input');
- $this->config = static::getService('config');
- }
-
- /**
- * Do the frontend integration generation.
- *
- * @return string
- */
- public function generate()
- {
- $this->mapService->handleAjaxRequest($this->getIdentifier());
-
- if (TL_MODE === 'BE') {
- $model = MapModel::findByPK($this->leaflet_map);
-
- $template = new \BackendTemplate('be_wildcard');
-
- if ($model) {
- $href = 'contao/main.php?do=leaflet&table=tl_leaflet_map&act=edit&id=' . $model->id;
-
- $template->wildcard = '### LEAFLET MAP ' . $model->title . ' ###';
- $template->title = $this->headline;
- $template->id = $model->id;
- $template->link = $model->title;
- $template->href = $href;
- }
-
- return $template->parse();
- }
-
- return parent::generate();
- }
-
- /**
- * Do the frontend integration compiling.
- *
- * @return void
- *
- * @throws \Exception If the map could not be created.
- *
- * @SuppressWarnings(PHPMD.Superglobals)
- */
- protected function compile()
- {
- try {
- $template = $this->leaflet_template ?: 'leaflet_map_js';
- $mapId = $this->getIdentifier();
- $map = $this->mapService->generate($this->leaflet_map, null, $mapId, $template);
-
- $GLOBALS['TL_BODY'][] = '';
-
- $this->Template->mapId = $mapId;
-
- $style = '';
- $height = deserialize($this->leaflet_height, true);
- $width = deserialize($this->leaflet_width, true);
-
- if (!empty($width['value'])) {
- $style .= 'width:' . $width['value'] . $width['unit'] . ';';
- }
-
- if (!empty($height['value'])) {
- $style .= 'height:' . $height['value'] . $height['unit'] . ';';
- }
-
- $this->Template->mapStyle = $style;
- } catch (\Exception $e) {
- throw $e;
- }
- }
-}
diff --git a/src/Netzmacht/Contao/Leaflet/Frontend/MapElement.php b/src/Netzmacht/Contao/Leaflet/Frontend/MapElement.php
index 826cbc2..3ebaf40 100644
--- a/src/Netzmacht/Contao/Leaflet/Frontend/MapElement.php
+++ b/src/Netzmacht/Contao/Leaflet/Frontend/MapElement.php
@@ -11,34 +11,19 @@
namespace Netzmacht\Contao\Leaflet\Frontend;
-use ContentElement;
-use Netzmacht\Contao\Toolkit\ServiceContainerTrait;
-use Netzmacht\Contao\Leaflet\MapService;
-
/**
* The content element for the leaflet map.
*
* @property int leaflet_map
*/
-class MapElement extends \ContentElement
+class MapElement extends AbstractMapHybrid
{
- use ServiceContainerTrait;
- use HybridTrait;
-
/**
* Template name.
*
* @var string
*/
- protected $strTemplate = 'ce_leaflet_map';
-
- /**
- * {@inheritdoc}
- */
- public function __construct($objElement, $strColumn = 'main')
- {
- $this->construct($objElement, $strColumn);
- }
+ protected $templateName = 'ce_leaflet_map';
/**
* Get the identifier.
@@ -47,14 +32,14 @@ class MapElement extends \ContentElement
*/
protected function getIdentifier()
{
- if ($this->leaflet_mapId) {
- return $this->leaflet_mapId;
+ if ($this->get('leaflet_mapId')) {
+ return $this->get('leaflet_mapId');
}
- if ($this->cssID[0]) {
- return 'map_' . $this->cssID[0];
+ if ($this->get('cssID')[0]) {
+ return 'map_' . $this->get('cssID')[0];
}
- return 'map_ce_' . $this->id;
+ return 'map_ce_' . $this->get('id');
}
}
diff --git a/src/Netzmacht/Contao/Leaflet/Frontend/MapModule.php b/src/Netzmacht/Contao/Leaflet/Frontend/MapModule.php
index 1e376ee..ad58ba1 100644
--- a/src/Netzmacht/Contao/Leaflet/Frontend/MapModule.php
+++ b/src/Netzmacht/Contao/Leaflet/Frontend/MapModule.php
@@ -11,33 +11,19 @@
namespace Netzmacht\Contao\Leaflet\Frontend;
-use Netzmacht\Contao\Toolkit\ServiceContainerTrait;
-use Netzmacht\Contao\Leaflet\MapService;
-
/**
* The frontend module for the Leaflet map.
*
* @package Netzmacht\Contao\Leaflet\Frontend
*/
-class MapModule extends \Module
+class MapModule extends AbstractMapHybrid
{
- use ServiceContainerTrait;
- use HybridTrait;
-
/**
* Template name.
*
* @var string
*/
- protected $strTemplate = 'mod_leaflet_map';
-
- /**
- * {@inheritdoc}
- */
- public function __construct($objElement, $strColumn = 'main')
- {
- $this->construct($objElement, $strColumn);
- }
+ protected $templateName = 'mod_leaflet_map';
/**
* Get the identifier.
@@ -46,14 +32,14 @@ class MapModule extends \Module
*/
protected function getIdentifier()
{
- if ($this->leaflet_mapId) {
- return $this->leaflet_mapId;
+ if ($this->get('leaflet_mapId')) {
+ return $this->get('leaflet_mapId');
}
- if ($this->cssID[0]) {
- return 'map_' . $this->cssID[0];
+ if ($this->get('cssID')[0]) {
+ return 'map_' . $this->get('cssID')[0];
}
- return 'map_mod_' . $this->id;
+ return 'map_mod_' . $this->get('id');
}
}
diff --git a/src/Netzmacht/Contao/Leaflet/Model/MapModel.php b/src/Netzmacht/Contao/Leaflet/Model/MapModel.php
index a3795f1..a5b4288 100644
--- a/src/Netzmacht/Contao/Leaflet/Model/MapModel.php
+++ b/src/Netzmacht/Contao/Leaflet/Model/MapModel.php
@@ -17,6 +17,8 @@ use Model\Collection;
* Class MapModel for the tl_leaflet_map table.
*
* @property mixed|null locate
+ * @property mixed|null title
+ *
* @package Netzmacht\Contao\Leaflet\Model
*/
class MapModel extends \Model