mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-01 20:43:52 +01:00
Refactor GeoJson subscriber.
This commit is contained in:
@@ -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