From cd88c2992b729cb3bac4349012753f0ab71249ab Mon Sep 17 00:00:00 2001 From: David Molineus Date: Mon, 9 Oct 2017 16:53:22 +0200 Subject: [PATCH] Fix type options. --- src/Listener/Dca/IconDcaListener.php | 50 +++++++++++++++++++ src/Listener/Dca/StyleDcaListener.php | 50 +++++++++++++++++++ src/Listener/Dca/VectorDcaListener.php | 31 ++++++++++++ src/Resources/config/listeners.yml | 11 ++++ src/Resources/contao/dca/tl_leaflet_icon.php | 2 +- src/Resources/contao/dca/tl_leaflet_style.php | 2 +- .../contao/dca/tl_leaflet_vector.php | 2 +- 7 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 src/Listener/Dca/IconDcaListener.php create mode 100644 src/Listener/Dca/StyleDcaListener.php diff --git a/src/Listener/Dca/IconDcaListener.php b/src/Listener/Dca/IconDcaListener.php new file mode 100644 index 0000000..89b1dc2 --- /dev/null +++ b/src/Listener/Dca/IconDcaListener.php @@ -0,0 +1,50 @@ + + * @copyright 2016-2017 netzmacht David Molineus. All rights reserved. + * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE + * @filesource + */ + +declare(strict_types=1); + +namespace Netzmacht\Contao\Leaflet\Listener\Dca; + +/** + * Class IconDcaListener. + * + * @package Netzmacht\Contao\Leaflet\Listener\Dca + */ +class IconDcaListener +{ + /** + * Icon type options. + * + * @var array + */ + private $icons; + + /** + * IconDcaListener constructor. + * + * @param array $icons Icon type options. + */ + public function __construct(array $icons) + { + $this->icons = $icons; + } + + /** + * Get icon options. + * + * @return array + */ + public function getIconOptions(): array + { + return $this->icons; + } +} diff --git a/src/Listener/Dca/StyleDcaListener.php b/src/Listener/Dca/StyleDcaListener.php new file mode 100644 index 0000000..c3389eb --- /dev/null +++ b/src/Listener/Dca/StyleDcaListener.php @@ -0,0 +1,50 @@ + + * @copyright 2016-2017 netzmacht David Molineus. All rights reserved. + * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE + * @filesource + */ + +declare(strict_types=1); + +namespace Netzmacht\Contao\Leaflet\Listener\Dca; + +/** + * Class StyleDcaListener. + * + * @package Netzmacht\Contao\Leaflet\Listener\Dca + */ +class StyleDcaListener +{ + /** + * Style type options. + * + * @var array + */ + private $icons; + + /** + * StyleDcaListener constructor. + * + * @param array $styles Styles options. + */ + public function __construct(array $styles) + { + $this->icons = $styles; + } + + /** + * Get style options. + * + * @return array + */ + public function getStyleOptions(): array + { + return $this->icons; + } +} diff --git a/src/Listener/Dca/VectorDcaListener.php b/src/Listener/Dca/VectorDcaListener.php index 4db7baa..4bc9571 100644 --- a/src/Listener/Dca/VectorDcaListener.php +++ b/src/Listener/Dca/VectorDcaListener.php @@ -14,6 +14,7 @@ namespace Netzmacht\Contao\Leaflet\Listener\Dca; use Netzmacht\Contao\Leaflet\Model\IconModel; use Netzmacht\Contao\Toolkit\Dca\Listener\AbstractListener; +use Netzmacht\Contao\Toolkit\Dca\Manager; use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder; use Netzmacht\Contao\Leaflet\Model\StyleModel; @@ -31,6 +32,36 @@ class VectorDcaListener extends AbstractListener */ protected static $name = 'tl_leaflet_vector'; + /** + * Vector options. + * + * @var array + */ + private $vectors; + + /** + * Construct. + * + * @param Manager $dcaManager Data container manager. + * @param array $vectors Vectors. + */ + public function __construct(Manager $dcaManager, array $vectors) + { + parent::__construct($dcaManager); + + $this->vectors = $vectors; + } + + /** + * Get the vector options. + * + * @return array + */ + public function getVectorOptions(): array + { + return $this->vectors; + } + /** * Generate the row label. * diff --git a/src/Resources/config/listeners.yml b/src/Resources/config/listeners.yml index 8a3a924..38fd9f2 100644 --- a/src/Resources/config/listeners.yml +++ b/src/Resources/config/listeners.yml @@ -48,6 +48,17 @@ services: class: Netzmacht\Contao\Leaflet\Listener\Dca\VectorDcaListener arguments: - '@netzmacht.contao_toolkit.dca.manager' + - '%netzmacht.contao_leaflet_maps.vectors%' + + netzmacht.contao_leaflet_maps.listeners.dca.icon: + class: Netzmacht\Contao\Leaflet\Listener\Dca\IconDcaListener + arguments: + - '%netzmacht.contao_leaflet_maps.icons%' + + netzmacht.contao_leaflet_maps.listeners.dca.style: + class: Netzmacht\Contao\Leaflet\Listener\Dca\IconDcaListener + arguments: + - '%netzmacht.contao_leaflet_maps.styles%' netzmacht.contao_leaflet_maps.listeners.geo_json_subscriber: class: Netzmacht\Contao\Leaflet\Subscriber\GeoJsonSubscriber diff --git a/src/Resources/contao/dca/tl_leaflet_icon.php b/src/Resources/contao/dca/tl_leaflet_icon.php index 17be690..e42238c 100644 --- a/src/Resources/contao/dca/tl_leaflet_icon.php +++ b/src/Resources/contao/dca/tl_leaflet_icon.php @@ -222,7 +222,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array 'submitOnChange' => true, 'chosen' => true, ), - 'options' => &$GLOBALS['LEAFLET_ICONS'], + 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.icon', 'getIconOptions'], 'reference' => &$GLOBALS['TL_LANG']['leaflet_icon'], 'sql' => "varchar(32) NOT NULL default ''" ), diff --git a/src/Resources/contao/dca/tl_leaflet_style.php b/src/Resources/contao/dca/tl_leaflet_style.php index 39c19d2..dec0168 100644 --- a/src/Resources/contao/dca/tl_leaflet_style.php +++ b/src/Resources/contao/dca/tl_leaflet_style.php @@ -188,7 +188,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_style'] = array 'submitOnChange' => true, 'chosen' => true, ), - 'options' => &$GLOBALS['LEAFLET_STYLES'], + 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.style', 'getStyleOptions'], 'reference' => &$GLOBALS['TL_LANG']['leaflet_style'], 'sql' => "varchar(32) NOT NULL default ''" ), diff --git a/src/Resources/contao/dca/tl_leaflet_vector.php b/src/Resources/contao/dca/tl_leaflet_vector.php index d5a13c9..99d0263 100644 --- a/src/Resources/contao/dca/tl_leaflet_vector.php +++ b/src/Resources/contao/dca/tl_leaflet_vector.php @@ -235,7 +235,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array 'chosen' => true, 'helpwizard' => true, ), - 'options' => &$GLOBALS['LEAFLET_VECTORS'], + 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.vector', 'getVectorOptions'], 'reference' => &$GLOBALS['TL_LANG']['leaflet_vector'], 'sql' => "varchar(32) NOT NULL default ''" ),