forked from Snck3rs/contao-leaflet-maps
Refactor GeoJson subscriber.
This commit is contained in:
@@ -11,5 +11,5 @@
|
||||
return array(
|
||||
$GLOBALS['container']['leaflet.boot.subscriber'],
|
||||
'Netzmacht\Contao\Leaflet\Subscriber\HashSubscriber',
|
||||
'Netzmacht\Contao\Leaflet\Subscriber\GeoJsonSubscriber',
|
||||
$GLOBALS['container']['leaflet.subscriber.geo-json'],
|
||||
);
|
||||
|
||||
@@ -24,6 +24,7 @@ use Netzmacht\Contao\Leaflet\Frontend\ValueFilter;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\MapProvider;
|
||||
use Netzmacht\Contao\Leaflet\Subscriber\BootSubscriber;
|
||||
use Netzmacht\Contao\Leaflet\Subscriber\GeoJsonSubscriber;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Filter\ExistingAliasFilter;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Filter\SlugifyFilter;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Filter\SuffixFilter;
|
||||
@@ -264,3 +265,9 @@ $container[Services::MODULES_MAP]['leaflet'] = function ($model, $column, Contai
|
||||
$column
|
||||
);
|
||||
};
|
||||
|
||||
$container['leaflet.subscriber.geo-json'] = $container->share(function () {
|
||||
return new GeoJsonSubscriber(
|
||||
$GLOBALS['LEAFLET_FEATURE_MODEL_PROPERTIES']
|
||||
);
|
||||
});
|
||||
|
||||
@@ -28,6 +28,23 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
*/
|
||||
class GeoJsonSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Property mapping between models and features.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $featureModelProperties;
|
||||
|
||||
/**
|
||||
* GeoJsonSubscriber constructor.
|
||||
*
|
||||
* @param array $featureModelProperties Property mapping between models and features.
|
||||
*/
|
||||
public function __construct(array $featureModelProperties)
|
||||
{
|
||||
$this->featureModelProperties = $featureModelProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -113,7 +130,6 @@ class GeoJsonSubscriber implements EventSubscriberInterface
|
||||
* @param ConvertToGeoJsonEvent $event The subscribed events.
|
||||
*
|
||||
* @return void
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function setModelData(ConvertToGeoJsonEvent $event)
|
||||
{
|
||||
@@ -121,11 +137,11 @@ class GeoJsonSubscriber implements EventSubscriberInterface
|
||||
$model = $event->getModel();
|
||||
|
||||
if (!$model instanceof \Model || !$feature instanceof Feature
|
||||
|| empty($GLOBALS['LEAFLET_FEATURE_MODEL_PROPERTIES'][$model->getTable()])) {
|
||||
|| empty($this->featureModelProperties[$model->getTable()])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mapping = $GLOBALS['LEAFLET_FEATURE_MODEL_PROPERTIES'][$model->getTable()];
|
||||
$mapping = $this->featureModelProperties[$model->getTable()];
|
||||
$data = (array) $feature->getProperty('model');
|
||||
|
||||
foreach ((array) $mapping as $property) {
|
||||
|
||||
Reference in New Issue
Block a user