forked from Snck3rs/contao-leaflet-maps
Rework components to support latest toolkit changes.
This commit is contained in:
@@ -22,7 +22,7 @@ use Contao\Model\Collection;
|
||||
use Netzmacht\Contao\Leaflet\MapProvider;
|
||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -56,24 +56,24 @@ abstract class AbstractMapHybrid extends AbstractHybrid
|
||||
/**
|
||||
* HybridTrait constructor.
|
||||
*
|
||||
* @param Result|Model|Collection $model Component model.
|
||||
* @param TemplateFactory $templateFactory Template factory.
|
||||
* @param Translator $translator Translator.
|
||||
* @param MapProvider $mapProvider Map provider.
|
||||
* @param Input $input Request Input.
|
||||
* @param Config $config Config.
|
||||
* @param string $column Column in which the element appears.
|
||||
* @param Result|Model|Collection $model Component model.
|
||||
* @param TemplateEngine $templateEngine Template engine.
|
||||
* @param Translator $translator Translator.
|
||||
* @param MapProvider $mapProvider Map provider.
|
||||
* @param Input $input Request Input.
|
||||
* @param Config $config Config.
|
||||
* @param string $column Column in which the element appears.
|
||||
*/
|
||||
public function __construct(
|
||||
$model,
|
||||
TemplateFactory $templateFactory,
|
||||
TemplateEngine $templateEngine,
|
||||
Translator $translator,
|
||||
MapProvider $mapProvider,
|
||||
$input,
|
||||
$config,
|
||||
$column = null
|
||||
) {
|
||||
parent::__construct($model, $templateFactory, $translator, $column);
|
||||
parent::__construct($model, $templateEngine, $translator, $column);
|
||||
|
||||
$this->mapProvider = $mapProvider;
|
||||
$this->input = $input;
|
||||
@@ -90,44 +90,38 @@ abstract class AbstractMapHybrid extends AbstractHybrid
|
||||
$this->mapProvider->handleAjaxRequest($this->getIdentifier());
|
||||
|
||||
if (TL_MODE === 'BE') {
|
||||
$model = MapModel::findByPk($this->get('leaflet_map'));
|
||||
|
||||
$template = $this->getTemplateFactory()->createBackendTemplate('be_wildcard');
|
||||
$model = MapModel::findByPk($this->get('leaflet_map'));
|
||||
$parameters = [
|
||||
'title' => $this->get('headline'),
|
||||
];
|
||||
|
||||
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 . ' ###');
|
||||
$template->set('title', $this->get('headline'));
|
||||
$template->set('id', $model->id);
|
||||
$template->set('link', $model->title);
|
||||
$template->set('href', $href);
|
||||
$parameters['wildcard'] = '### LEAFLET MAP ' . $model->title . ' ###';
|
||||
$parameters['id'] = $model->id;
|
||||
$parameters['link'] = $model->title;
|
||||
$parameters['href'] = $href;
|
||||
}
|
||||
|
||||
return $template->parse();
|
||||
return $this->render('toolkit:be:be_wildcard.html5', $parameters);
|
||||
}
|
||||
|
||||
return parent::generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the frontend integration compiling.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception If the map could not be created.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function compile(): void
|
||||
protected function prepareTemplateData(array $data): array
|
||||
{
|
||||
try {
|
||||
$template = $this->get('leaflet_template') ?: 'leaflet_map_js';
|
||||
$mapId = $this->getIdentifier();
|
||||
$map = $this->mapProvider->generate($this->get('leaflet_map'), null, $mapId, $template);
|
||||
|
||||
$this->template->set('javascript', $map);
|
||||
$this->template->set('mapId', $mapId);
|
||||
$data['javascript'] = $map;
|
||||
$data['mapId'] = $mapId;
|
||||
|
||||
$style = '';
|
||||
$height = deserialize($this->get('leaflet_height'), true);
|
||||
@@ -141,10 +135,12 @@ abstract class AbstractMapHybrid extends AbstractHybrid
|
||||
$style .= 'height:' . $height['value'] . $height['unit'] . ';';
|
||||
}
|
||||
|
||||
$this->template->set('mapStyle', $style);
|
||||
$data['mapStyle'] = $style;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user