diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php index 8d796d3..9e1e67a 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php @@ -151,13 +151,18 @@ abstract class AbstractMapper implements Mapper /** * {@inheritdoc} */ - public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null) - { + public function handle( + $model, + DefinitionMapper $mapper, + LatLngBounds $bounds = null, + $elementId = null, + Definition $parent = null + ) { $definition = $this->createInstance($model, $mapper, $bounds, $elementId); $this->buildOptions($definition, $model); $this->buildConditionals($definition, $model); - $this->build($definition, $model, $mapper, $bounds); + $this->build($definition, $model, $mapper, $bounds, $parent); return $definition; } @@ -188,6 +193,7 @@ abstract class AbstractMapper implements Mapper * @param \Model $model The model. * @param DefinitionMapper $mapper The definition mapper. * @param LatLngBounds $bounds Optional bounds where elements should be in. + * @param Definition|null $parent The parent object. * * @return void * @@ -197,7 +203,8 @@ abstract class AbstractMapper implements Mapper Definition $definition, \Model $model, DefinitionMapper $mapper, - LatLngBounds $bounds = null + LatLngBounds $bounds = null, + Definition $parent = null ) { } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Control/AttributionControlMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Control/AttributionControlMapper.php index 6a777af..b829f0c 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Control/AttributionControlMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Control/AttributionControlMapper.php @@ -53,8 +53,9 @@ class AttributionControlMapper extends AbstractControlMapper protected function build( Definition $definition, \Model $model, - DefinitionMapper $builder, - LatLngBounds $bounds = null + DefinitionMapper $mapper, + LatLngBounds $bounds = null, + Definition $parent = null ) { if (!$definition instanceof Attribution) { return; diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Control/LoadingControlMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Control/LoadingControlMapper.php index 4da2b10..1d0b067 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Control/LoadingControlMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Control/LoadingControlMapper.php @@ -69,7 +69,8 @@ class LoadingControlMapper extends AbstractControlMapper Definition $definition, \Model $model, DefinitionMapper $mapper, - LatLngBounds $bounds = null + LatLngBounds $bounds = null, + Definition $parent = null ) { parent::build($definition, $model, $mapper, $bounds); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/DefinitionMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/DefinitionMapper.php index 8b26432..2048d8d 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/DefinitionMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/DefinitionMapper.php @@ -77,15 +77,16 @@ class DefinitionMapper /** * Build a model. * - * @param mixed $model The definition model. - * @param LatLngBounds $bounds Optional bounds where elements should be in. - * @param string $elementId Optional element id. If none given the mapId or alias is used. + * @param mixed $model The definition model. + * @param LatLngBounds $bounds Optional bounds where elements should be in. + * @param string $elementId Optional element id. If none given the mapId or alias is used. + * @param Definition|null $parent Optional pass the parent object. * * @return Definition|null * * @throws \RuntimeException If model could not be mapped to a definition. */ - public function handle($model, LatLngBounds $bounds = null, $elementId = null) + public function handle($model, LatLngBounds $bounds = null, $elementId = null, $parent = null) { $hash = $this->getHash($model, $elementId); @@ -96,7 +97,7 @@ class DefinitionMapper foreach ($this->builders as $builders) { foreach ($builders as $builder) { if ($builder->match($model)) { - $definition = $builder->handle($model, $this, $bounds, $elementId); + $definition = $builder->handle($model, $this, $bounds, $elementId, $parent); if ($definition) { $event = new BuildDefinitionEvent($definition, $model, $bounds); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/GroupLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/GroupLayerMapper.php index 9c5eb6d..f88927d 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/GroupLayerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/GroupLayerMapper.php @@ -58,7 +58,8 @@ class GroupLayerMapper extends AbstractLayerMapper Definition $definition, \Model $model, DefinitionMapper $mapper, - LatLngBounds $bounds = null + LatLngBounds $bounds = null, + Definition $parent = null ) { if (!$definition instanceof LayerGroup) { return; diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php index 84fac21..0929dd2 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php @@ -86,7 +86,8 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper Definition $definition, \Model $model, DefinitionMapper $mapper, - LatLngBounds $bounds = null + LatLngBounds $bounds = null, + Definition $parent = null ) { if ($definition instanceof GeoJson) { $collection = $this->loadMarkerModels($model); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ProviderLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ProviderLayerMapper.php index 0058448..392fd48 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ProviderLayerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ProviderLayerMapper.php @@ -73,8 +73,9 @@ class ProviderLayerMapper extends AbstractLayerMapper protected function build( Definition $definition, \Model $model, - DefinitionMapper $builder, - LatLngBounds $bounds = null + DefinitionMapper $mapper, + LatLngBounds $bounds = null, + Definition $parent = null ) { if (!empty($this->providers[$model->tile_provider]['options'])) { $this->applyOptions( diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ReferenceLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ReferenceLayerMapper.php index 0b5658f..abba625 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ReferenceLayerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ReferenceLayerMapper.php @@ -13,6 +13,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\LayerModel; +use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; /** @@ -32,7 +33,7 @@ class ReferenceLayerMapper extends AbstractLayerMapper /** * {@inheritdoc} */ - public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null) + public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null, Definition $parent = null) { $reference = LayerModel::findByPk($model->reference); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php index 377008b..e431647 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php @@ -100,7 +100,8 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper Definition $definition, \Model $model, DefinitionMapper $mapper, - LatLngBounds $bounds = null + LatLngBounds $bounds = null, + Definition $parent = null ) { if ($definition instanceof GeoJson) { $collection = $this->loadVectorModels($model); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php index 9a15469..942a4bd 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php @@ -57,12 +57,17 @@ class MapMapper extends AbstractMapper /** * {@inheritdoc} */ - protected function build(Definition $map, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null) - { + protected function build( + Definition $map, + \Model $model, + DefinitionMapper $mapper, + LatLngBounds $bounds = null, + Definition $parent = null + ) { if ($map instanceof Map && $model instanceof MapModel) { $this->buildCustomOptions($map, $model); - $this->buildControls($map, $model, $builder, $bounds); - $this->buildLayers($map, $model, $builder, $bounds); + $this->buildControls($map, $model, $mapper, $bounds); + $this->buildLayers($map, $model, $mapper, $bounds); $this->buildBoundsCalculation($map, $model); } } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php index 393b317..e7a3dee 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php @@ -27,11 +27,18 @@ interface Mapper * @param \Model|mixed $model The model being built. Usually a contao model, but can be anything. * @param DefinitionMapper $mapper The definition builder. * @param LatLngBounds $bounds Optional bounds where elements should be in. - * @param string $elementId Optional element id. + * @param string $elementId Optional element. + * @param Definition|null $parent Optional passed parent. * * @return Definition */ - public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null); + public function handle( + $model, + DefinitionMapper $mapper, + LatLngBounds $bounds = null, + $elementId = null, + Definition $parent = null + ); /** * Check if mapper is responsible for the model. diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Type/DivIconMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Type/DivIconMapper.php index 5c038c8..34ca4b3 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Type/DivIconMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Type/DivIconMapper.php @@ -54,7 +54,8 @@ class DivIconMapper extends AbstractIconMapper Definition $definition, \Model $model, DefinitionMapper $mapper, - LatLngBounds $bounds = null + LatLngBounds $bounds = null, + Definition $parent = null ) { parent::build($definition, $model, $mapper, $bounds); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Type/ImageIconMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Type/ImageIconMapper.php index eeac264..68dde93 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Type/ImageIconMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Type/ImageIconMapper.php @@ -67,7 +67,8 @@ class ImageIconMapper extends AbstractIconMapper Definition $definition, \Model $model, DefinitionMapper $mapper, - LatLngBounds $bounds = null + LatLngBounds $bounds = null, + Definition $parent = null ) { if ($definition instanceof ImageIcon) { $this->addIcon($definition, $model); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php index 7a68981..0cf6804 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php @@ -73,8 +73,9 @@ class MarkerMapper extends AbstractMapper protected function build( Definition $definition, \Model $model, - DefinitionMapper $builder, - LatLngBounds $bounds = null + DefinitionMapper $mapper, + LatLngBounds $bounds = null, + Definition $parent = null ) { if ($definition instanceof Marker) { if ($model->addPopup) { @@ -90,7 +91,7 @@ class MarkerMapper extends AbstractMapper if ($iconModel) { /** @var ImageIcon $icon */ - $icon = $builder->handle($iconModel); + $icon = $mapper->handle($iconModel); $definition->setIcon($icon); } } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php index dbb5766..5e57d7d 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php @@ -41,7 +41,8 @@ class AbstractVectorMapper extends AbstractTypeMapper Definition $definition, \Model $model, DefinitionMapper $mapper, - LatLngBounds $bounds = null + LatLngBounds $bounds = null, + Definition $parent = null ) { parent::build($definition, $model, $mapper, $bounds); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/CircleMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/CircleMapper.php index 926c92e..75c08ba 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/CircleMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/CircleMapper.php @@ -54,10 +54,11 @@ class CircleMapper extends AbstractVectorMapper protected function build( Definition $definition, \Model $model, - DefinitionMapper $builder, - LatLngBounds $bounds = null + DefinitionMapper $mapper, + LatLngBounds $bounds = null, + Definition $parent = null ) { - parent::build($definition, $model, $builder, $bounds); + parent::build($definition, $model, $mapper, $bounds); if ($definition instanceof Circle) { $definition->setLatLng(LatLng::fromString($model->coordinates)); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolygonMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolygonMapper.php index e03e6dd..975ae85 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolygonMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolygonMapper.php @@ -44,10 +44,11 @@ class MultiPolygonMapper extends MultiPolylineMapper protected function build( Definition $definition, \Model $model, - DefinitionMapper $builder, - LatLngBounds $bounds = null + DefinitionMapper $mapper, + LatLngBounds $bounds = null, + Definition $parent = null ) { - parent::build($definition, $model, $builder, $bounds); + parent::build($definition, $model, $mapper, $bounds); if ($definition instanceof MultiPolygon) { $this->createLatLngs($definition, $model); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolylineMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolylineMapper.php index 9bf143d..d529e62 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolylineMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolylineMapper.php @@ -45,10 +45,11 @@ class MultiPolylineMapper extends AbstractVectorMapper protected function build( Definition $definition, \Model $model, - DefinitionMapper $builder, - LatLngBounds $bounds = null + DefinitionMapper $mapper, + LatLngBounds $bounds = null, + Definition $parent = null ) { - parent::build($definition, $model, $builder, $bounds); + parent::build($definition, $model, $mapper, $bounds); if ($definition instanceof MultiPolyline) { $this->createLatLngs($definition, $model); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/PolylineMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/PolylineMapper.php index f8d70e3..bc7fd3e 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/PolylineMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/PolylineMapper.php @@ -44,10 +44,11 @@ class PolylineMapper extends AbstractVectorMapper protected function build( Definition $definition, \Model $model, - DefinitionMapper $builder, - LatLngBounds $bounds = null + DefinitionMapper $mapper, + LatLngBounds $bounds = null, + Definition $parent = null ) { - parent::build($definition, $model, $builder, $bounds); + parent::build($definition, $model, $mapper, $bounds); if ($definition instanceof Polyline) { array_map(