Rework components to support latest toolkit changes.

This commit is contained in:
David Molineus
2017-10-10 15:25:35 +02:00
parent 5167318c43
commit 8f45bf925a
5 changed files with 31 additions and 53 deletions

View File

@@ -22,7 +22,7 @@ use Contao\Model\Collection;
use Netzmacht\Contao\Leaflet\MapProvider; use Netzmacht\Contao\Leaflet\MapProvider;
use Netzmacht\Contao\Leaflet\Model\MapModel; use Netzmacht\Contao\Leaflet\Model\MapModel;
use Netzmacht\Contao\Toolkit\Component\Hybrid\AbstractHybrid; use Netzmacht\Contao\Toolkit\Component\Hybrid\AbstractHybrid;
use Netzmacht\Contao\Toolkit\View\Template\TemplateFactory; use Symfony\Component\Templating\EngineInterface as TemplateEngine;
use Symfony\Component\Translation\TranslatorInterface as Translator; use Symfony\Component\Translation\TranslatorInterface as Translator;
/** /**
@@ -56,24 +56,24 @@ abstract class AbstractMapHybrid extends AbstractHybrid
/** /**
* HybridTrait constructor. * HybridTrait constructor.
* *
* @param Result|Model|Collection $model Component model. * @param Result|Model|Collection $model Component model.
* @param TemplateFactory $templateFactory Template factory. * @param TemplateEngine $templateEngine Template engine.
* @param Translator $translator Translator. * @param Translator $translator Translator.
* @param MapProvider $mapProvider Map provider. * @param MapProvider $mapProvider Map provider.
* @param Input $input Request Input. * @param Input $input Request Input.
* @param Config $config Config. * @param Config $config Config.
* @param string $column Column in which the element appears. * @param string $column Column in which the element appears.
*/ */
public function __construct( public function __construct(
$model, $model,
TemplateFactory $templateFactory, TemplateEngine $templateEngine,
Translator $translator, Translator $translator,
MapProvider $mapProvider, MapProvider $mapProvider,
$input, $input,
$config, $config,
$column = null $column = null
) { ) {
parent::__construct($model, $templateFactory, $translator, $column); parent::__construct($model, $templateEngine, $translator, $column);
$this->mapProvider = $mapProvider; $this->mapProvider = $mapProvider;
$this->input = $input; $this->input = $input;
@@ -90,44 +90,38 @@ abstract class AbstractMapHybrid extends AbstractHybrid
$this->mapProvider->handleAjaxRequest($this->getIdentifier()); $this->mapProvider->handleAjaxRequest($this->getIdentifier());
if (TL_MODE === 'BE') { if (TL_MODE === 'BE') {
$model = MapModel::findByPk($this->get('leaflet_map')); $model = MapModel::findByPk($this->get('leaflet_map'));
$parameters = [
$template = $this->getTemplateFactory()->createBackendTemplate('be_wildcard'); 'title' => $this->get('headline'),
];
if ($model) { if ($model) {
$href = 'contao/main.php?do=leaflet&table=tl_leaflet_map&act=edit&id=' . $model->id; $href = 'contao/main.php?do=leaflet&table=tl_leaflet_map&act=edit&id=' . $model->id;;
$template->set('wildcard', '### LEAFLET MAP ' . $model->title . ' ###'); $parameters['wildcard'] = '### LEAFLET MAP ' . $model->title . ' ###';
$template->set('title', $this->get('headline')); $parameters['id'] = $model->id;
$template->set('id', $model->id); $parameters['link'] = $model->title;
$template->set('link', $model->title); $parameters['href'] = $href;
$template->set('href', $href);
} }
return $template->parse(); return $this->render('toolkit:be:be_wildcard.html5', $parameters);
} }
return parent::generate(); return parent::generate();
} }
/** /**
* Do the frontend integration compiling. * {@inheritdoc}
*
* @return void
*
* @throws \Exception If the map could not be created.
*
* @SuppressWarnings(PHPMD.Superglobals)
*/ */
protected function compile(): void protected function prepareTemplateData(array $data): array
{ {
try { try {
$template = $this->get('leaflet_template') ?: 'leaflet_map_js'; $template = $this->get('leaflet_template') ?: 'leaflet_map_js';
$mapId = $this->getIdentifier(); $mapId = $this->getIdentifier();
$map = $this->mapProvider->generate($this->get('leaflet_map'), null, $mapId, $template); $map = $this->mapProvider->generate($this->get('leaflet_map'), null, $mapId, $template);
$this->template->set('javascript', $map); $data['javascript'] = $map;
$this->template->set('mapId', $mapId); $data['mapId'] = $mapId;
$style = ''; $style = '';
$height = deserialize($this->get('leaflet_height'), true); $height = deserialize($this->get('leaflet_height'), true);
@@ -141,10 +135,12 @@ abstract class AbstractMapHybrid extends AbstractHybrid
$style .= 'height:' . $height['value'] . $height['unit'] . ';'; $style .= 'height:' . $height['value'] . $height['unit'] . ';';
} }
$this->template->set('mapStyle', $style); $data['mapStyle'] = $style;
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
} }
return $data;
} }
/** /**

View File

@@ -14,7 +14,6 @@ declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Frontend\ContentElement; namespace Netzmacht\Contao\Leaflet\Frontend\ContentElement;
use Netzmacht\Contao\Leaflet\Frontend\ContentElement\MapElement;
use Netzmacht\Contao\Toolkit\Component\Component; use Netzmacht\Contao\Toolkit\Component\Component;
use Netzmacht\Contao\Toolkit\Component\ComponentFactory; use Netzmacht\Contao\Toolkit\Component\ComponentFactory;
use Psr\Container\ContainerInterface as Container; use Psr\Container\ContainerInterface as Container;
@@ -58,7 +57,7 @@ class MapElementFactory implements ComponentFactory
{ {
return new MapElement( return new MapElement(
$model, $model,
$this->container->get('netzmacht.contao_toolkit.view.template_factory'), $this->container->get('templating'),
$this->container->get('translator'), $this->container->get('translator'),
$this->container->get('netzmacht.contao_leaflet_maps.map.provider'), $this->container->get('netzmacht.contao_leaflet_maps.map.provider'),
$this->container->get('netzmacht.contao_toolkit.contao.input'), $this->container->get('netzmacht.contao_toolkit.contao.input'),

View File

@@ -14,7 +14,6 @@ declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Frontend\Module; namespace Netzmacht\Contao\Leaflet\Frontend\Module;
use Netzmacht\Contao\Leaflet\Frontend\Module\MapModule;
use Netzmacht\Contao\Toolkit\Component\Component; use Netzmacht\Contao\Toolkit\Component\Component;
use Netzmacht\Contao\Toolkit\Component\ComponentFactory; use Netzmacht\Contao\Toolkit\Component\ComponentFactory;
use Psr\Container\ContainerInterface as Container; use Psr\Container\ContainerInterface as Container;
@@ -58,7 +57,7 @@ class MapModuleFactory implements ComponentFactory
{ {
return new MapModule( return new MapModule(
$model, $model,
$this->container->get('netzmacht.contao_toolkit.view.template_factory'), $this->container->get('templating'),
$this->container->get('translator'), $this->container->get('translator'),
$this->container->get('netzmacht.contao_leaflet_maps.map.provider'), $this->container->get('netzmacht.contao_leaflet_maps.map.provider'),
$this->container->get('netzmacht.contao_toolkit.contao.input'), $this->container->get('netzmacht.contao_toolkit.contao.input'),

View File

@@ -83,6 +83,7 @@ services:
- '@service_container' - '@service_container'
tags: tags:
- { name: 'netzmacht.contao_toolkit.component.content_element_factory' } - { name: 'netzmacht.contao_toolkit.component.content_element_factory' }
- { name: 'netzmacht.contao_toolkit.component.content_element', alias: 'leaflet', category: 'include' }
netzmacht.contao_leaflet_maps.frontend.module_factory: netzmacht.contao_leaflet_maps.frontend.module_factory:
class: Netzmacht\Contao\Leaflet\Frontend\Module\MapModuleFactory class: Netzmacht\Contao\Leaflet\Frontend\Module\MapModuleFactory
@@ -90,6 +91,7 @@ services:
- '@service_container' - '@service_container'
tags: tags:
- { name: 'netzmacht.contao_toolkit.component.frontend_module_factory' } - { name: 'netzmacht.contao_toolkit.component.frontend_module_factory' }
- { name: 'netzmacht.contao_toolkit.component.frontend_module', alias: 'leaflet', category: include }
netzmacht.contao_leaflet_maps.frontend.insert_tag: netzmacht.contao_leaflet_maps.frontend.insert_tag:
class: Netzmacht\Contao\Leaflet\Frontend\InsertTag\LeafletInsertTagParser class: Netzmacht\Contao\Leaflet\Frontend\InsertTag\LeafletInsertTagParser

View File

@@ -10,9 +10,6 @@
* @filesource * @filesource
*/ */
use Netzmacht\Contao\Toolkit\Component\ContentElement\ContentElementDecorator;
use Netzmacht\Contao\Toolkit\Component\Module\ModuleDecorator;
/* /*
* Backend module. * Backend module.
*/ */
@@ -57,21 +54,6 @@ array_insert(
) )
); );
/*
* Content elements.
*/
$GLOBALS['TL_CTE']['includes']['leaflet'] = ContentElementDecorator::class;
/*
* Frontend modules
*/
$GLOBALS['FE_MOD']['includes']['leaflet'] = ModuleDecorator::class;
/* /*
* Models. * Models.
*/ */