mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-02 04:53:56 +01:00
Move content element to frontend folder.
This commit is contained in:
105
src/Netzmacht/Contao/Leaflet/Frontend/MapElement.php
Normal file
105
src/Netzmacht/Contao/Leaflet/Frontend/MapElement.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Frontend;
|
||||
|
||||
use ContentElement;
|
||||
use Netzmacht\Contao\Leaflet\MapService;
|
||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||
|
||||
/**
|
||||
* @property int leaflet_map
|
||||
*/
|
||||
class MapElement extends \ContentElement
|
||||
{
|
||||
/**
|
||||
* Template name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $strTemplate = 'ce_leaflet_map';
|
||||
|
||||
/**
|
||||
* @var MapService
|
||||
*/
|
||||
private $mapService;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param \ContentModel $objElement Content element model.
|
||||
* @param string $strColumn Layout column.
|
||||
*/
|
||||
public function __construct($objElement, $strColumn = 'main')
|
||||
{
|
||||
parent::__construct($objElement, $strColumn);
|
||||
|
||||
$this->mapService = $GLOBALS['container']['leaflet.map.service'];
|
||||
}
|
||||
|
||||
public function generate()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the content element.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function compile()
|
||||
{
|
||||
try {
|
||||
$mapId = 'map_' . ($this->cssID[0] ?: $this->id);
|
||||
$map = $this->mapService->getJavascript($this->leaflet_map, null, $mapId);
|
||||
|
||||
$GLOBALS['TL_BODY'][] = '<script>' . $map .'</script>';
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/Netzmacht/Contao/Leaflet/Frontend/MapModule.php
Normal file
18
src/Netzmacht/Contao/Leaflet/Frontend/MapModule.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2015 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Frontend;
|
||||
|
||||
|
||||
class MapModule
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user