forked from Snck3rs/contao-leaflet-maps
Replace insert tags and masked entities. (Fix #17)
This commit is contained in:
@@ -10,8 +10,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use Netzmacht\Contao\Leaflet\Boot;
|
use Netzmacht\Contao\Leaflet\Boot;
|
||||||
|
use Netzmacht\Contao\Leaflet\Frontend\Helper\FrontendApi;
|
||||||
|
use Netzmacht\Contao\Leaflet\Frontend\ValueFilter;
|
||||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||||
use Netzmacht\Contao\Leaflet\MapService;
|
use Netzmacht\Contao\Leaflet\MapService;
|
||||||
|
use Netzmacht\Contao\Leaflet\ServiceContainer;
|
||||||
use Netzmacht\JavascriptBuilder\Builder;
|
use Netzmacht\JavascriptBuilder\Builder;
|
||||||
use Netzmacht\JavascriptBuilder\Encoder;
|
use Netzmacht\JavascriptBuilder\Encoder;
|
||||||
use Netzmacht\JavascriptBuilder\Encoder\Chain\MultipleChain;
|
use Netzmacht\JavascriptBuilder\Encoder\Chain\MultipleChain;
|
||||||
@@ -100,3 +103,11 @@ $container['leaflet.definition.builder'] = $container->share(function($container
|
|||||||
|
|
||||||
return $boot->initializeLeafletBuilder($leaflet);
|
return $boot->initializeLeafletBuilder($leaflet);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$container['leaflet.frontend.value-filter'] = $container->share(function() {
|
||||||
|
return new ValueFilter(new FrontendApi());
|
||||||
|
});
|
||||||
|
|
||||||
|
$container['leaflet.service-container'] = $container->share(function($container) {
|
||||||
|
return new ServiceContainer($container);
|
||||||
|
});
|
||||||
|
|||||||
28
src/Netzmacht/Contao/Leaflet/Frontend/Helper/FrontendApi.php
Normal file
28
src/Netzmacht/Contao/Leaflet/Frontend/Helper/FrontendApi.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?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\Helper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FrontendApi provides access to the frontend api of contao.
|
||||||
|
*
|
||||||
|
* @package Netzmacht\Contao\Leaflet\Frontend\Helper
|
||||||
|
*/
|
||||||
|
class FrontendApi extends \Frontend
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function replaceInsertTags($strBuffer, $blnCache = true)
|
||||||
|
{
|
||||||
|
return parent::replaceInsertTags($strBuffer, $blnCache);
|
||||||
|
}
|
||||||
|
}
|
||||||
54
src/Netzmacht/Contao/Leaflet/Frontend/ValueFilter.php
Normal file
54
src/Netzmacht/Contao/Leaflet/Frontend/ValueFilter.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use Netzmacht\Contao\Leaflet\Frontend\Helper\FrontendApi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ValueFilter is a service class which can be used to filter values before passing them to an definition object.
|
||||||
|
*
|
||||||
|
* @package Netzmacht\Contao\Leaflet\Frontend
|
||||||
|
*/
|
||||||
|
class ValueFilter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The frontend api of Contao.
|
||||||
|
*
|
||||||
|
* @var FrontendApi
|
||||||
|
*/
|
||||||
|
private $api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct.
|
||||||
|
*
|
||||||
|
* @param FrontendApi $api The frontend api of Contao.
|
||||||
|
*/
|
||||||
|
public function __construct($api)
|
||||||
|
{
|
||||||
|
$this->api = $api;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter a value so it can be passed to the frontend.
|
||||||
|
*
|
||||||
|
* The idea behind this extra method is that we just have to change one place if anything else than the
|
||||||
|
* insert tags has to be replaced.
|
||||||
|
*
|
||||||
|
* @param string $value The given value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function filter($value)
|
||||||
|
{
|
||||||
|
return $this->api->replaceInsertTags($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\UI;
|
|||||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper;
|
use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper;
|
||||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||||
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||||
|
use Netzmacht\Contao\Leaflet\ServiceContainerTrait;
|
||||||
use Netzmacht\LeafletPHP\Definition;
|
use Netzmacht\LeafletPHP\Definition;
|
||||||
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
|
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
|
||||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||||
@@ -26,6 +27,8 @@ use Netzmacht\LeafletPHP\Definition\UI\Marker;
|
|||||||
*/
|
*/
|
||||||
class MarkerMapper extends AbstractMapper
|
class MarkerMapper extends AbstractMapper
|
||||||
{
|
{
|
||||||
|
use ServiceContainerTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class of the model being build.
|
* Class of the model being build.
|
||||||
*
|
*
|
||||||
@@ -79,7 +82,12 @@ class MarkerMapper extends AbstractMapper
|
|||||||
) {
|
) {
|
||||||
if ($definition instanceof Marker) {
|
if ($definition instanceof Marker) {
|
||||||
if ($model->addPopup) {
|
if ($model->addPopup) {
|
||||||
$definition->bindPopup($model->popupContent);
|
$content = $this
|
||||||
|
->getServiceContainer()
|
||||||
|
->getFrontendValueFilter()
|
||||||
|
->filter($model->popupContent);
|
||||||
|
|
||||||
|
$definition->bindPopup($content);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($model->customIcon) {
|
if ($model->customIcon) {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use Netzmacht\Contao\Leaflet\Definition\Style;
|
|||||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
|
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
|
||||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||||
use Netzmacht\Contao\Leaflet\Model\StyleModel;
|
use Netzmacht\Contao\Leaflet\Model\StyleModel;
|
||||||
|
use Netzmacht\Contao\Leaflet\ServiceContainerTrait;
|
||||||
use Netzmacht\LeafletPHP\Definition;
|
use Netzmacht\LeafletPHP\Definition;
|
||||||
use Netzmacht\LeafletPHP\Definition\HasPopup;
|
use Netzmacht\LeafletPHP\Definition\HasPopup;
|
||||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||||
@@ -27,6 +28,8 @@ use Netzmacht\LeafletPHP\Definition\Vector\Path;
|
|||||||
*/
|
*/
|
||||||
class AbstractVectorMapper extends AbstractTypeMapper
|
class AbstractVectorMapper extends AbstractTypeMapper
|
||||||
{
|
{
|
||||||
|
use ServiceContainerTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class of the model being build.
|
* Class of the model being build.
|
||||||
*
|
*
|
||||||
@@ -59,7 +62,12 @@ class AbstractVectorMapper extends AbstractTypeMapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($definition instanceof HasPopup && $model->addPopup) {
|
if ($definition instanceof HasPopup && $model->addPopup) {
|
||||||
$definition->bindPopup($model->popupContent);
|
$content = $this
|
||||||
|
->getServiceContainer()
|
||||||
|
->getFrontendValueFilter()
|
||||||
|
->filter($model->popupContent);
|
||||||
|
|
||||||
|
$definition->bindPopup($content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
61
src/Netzmacht/Contao/Leaflet/ServiceContainer.php
Normal file
61
src/Netzmacht/Contao/Leaflet/ServiceContainer.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use Netzmacht\Contao\Leaflet\Frontend\ValueFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ServiceContainer
|
||||||
|
*
|
||||||
|
* @package Netzmacht\Contao\Leaflet
|
||||||
|
*/
|
||||||
|
class ServiceContainer
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The global service container.
|
||||||
|
*
|
||||||
|
* @var \Pimple
|
||||||
|
*/
|
||||||
|
private $container;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct.
|
||||||
|
*
|
||||||
|
* @param \Pimple $container The global service container.
|
||||||
|
*/
|
||||||
|
public function __construct(\Pimple $container)
|
||||||
|
{
|
||||||
|
$this->container = $container;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value filter service.
|
||||||
|
*
|
||||||
|
* @return ValueFilter
|
||||||
|
*/
|
||||||
|
public function getFrontendValueFilter()
|
||||||
|
{
|
||||||
|
return $this->getService('leaflet.frontend.value-filter');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a service from the container.
|
||||||
|
*
|
||||||
|
* @param string $name The service name.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getService($name)
|
||||||
|
{
|
||||||
|
return $this->container[$name];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/Netzmacht/Contao/Leaflet/ServiceContainerTrait.php
Normal file
30
src/Netzmacht/Contao/Leaflet/ServiceContainerTrait.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ServiceContainerTrait provides simple access to the service container.
|
||||||
|
*
|
||||||
|
* @package Netzmacht\Contao\Leaflet
|
||||||
|
*/
|
||||||
|
trait ServiceContainerTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the service container.
|
||||||
|
*
|
||||||
|
* @return ServiceContainer
|
||||||
|
*/
|
||||||
|
protected function getServiceContainer()
|
||||||
|
{
|
||||||
|
return $GLOBALS['container']['leaflet.service-container'];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user