From ad6482c28c24bf9199c85eac2ddfb97d7d4158bd Mon Sep 17 00:00:00 2001 From: David Molineus Date: Fri, 6 Oct 2017 13:47:13 +0200 Subject: [PATCH] Rework vector dca callbacks to a service listener. --- .../Dca/VectorDcaListener.php} | 32 +++++++++++++------ src/Resources/config/listeners.yml | 5 +++ .../contao/dca/tl_leaflet_vector.php | 6 ++-- 3 files changed, 30 insertions(+), 13 deletions(-) rename src/{Dca/VectorCallbacks.php => Listener/Dca/VectorDcaListener.php} (68%) diff --git a/src/Dca/VectorCallbacks.php b/src/Listener/Dca/VectorDcaListener.php similarity index 68% rename from src/Dca/VectorCallbacks.php rename to src/Listener/Dca/VectorDcaListener.php index 034e72a..4db7baa 100644 --- a/src/Dca/VectorCallbacks.php +++ b/src/Listener/Dca/VectorDcaListener.php @@ -10,9 +10,10 @@ * @filesource */ -namespace Netzmacht\Contao\Leaflet\Dca; +namespace Netzmacht\Contao\Leaflet\Listener\Dca; -use Netzmacht\Contao\Toolkit\Dca\Callback\Callbacks; +use Netzmacht\Contao\Leaflet\Model\IconModel; +use Netzmacht\Contao\Toolkit\Dca\Listener\AbstractListener; use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder; use Netzmacht\Contao\Leaflet\Model\StyleModel; @@ -21,7 +22,7 @@ use Netzmacht\Contao\Leaflet\Model\StyleModel; * * @package Netzmacht\Contao\Leaflet\Dca */ -class VectorCallbacks extends Callbacks +class VectorDcaListener extends AbstractListener { /** * Name of the data container. @@ -30,13 +31,6 @@ class VectorCallbacks extends Callbacks */ protected static $name = 'tl_leaflet_vector'; - /** - * Helper service name. - * - * @var string - */ - protected static $serviceName = 'leaflet.dca.vector-callbacks'; - /** * Generate the row label. * @@ -64,4 +58,22 @@ class VectorCallbacks extends Callbacks return OptionsBuilder::fromCollection($collection, 'title')->getOptions(); } + + /** + * Get all icons. + * + * @return array + */ + public function getIcons() + { + $collection = IconModel::findAll(array('order' => 'title')); + $builder = OptionsBuilder::fromCollection( + $collection, + function ($model) { + return sprintf('%s [%s]', $model['title'], $model['type']); + } + ); + + return $builder->getOptions(); + } } diff --git a/src/Resources/config/listeners.yml b/src/Resources/config/listeners.yml index 7ece7ff..983ed06 100644 --- a/src/Resources/config/listeners.yml +++ b/src/Resources/config/listeners.yml @@ -26,3 +26,8 @@ services: class: Netzmacht\Contao\Leaflet\Listener\Dca\MarkerDcaListener arguments: - '@database_connection' + + netzmacht.contao_leaflet_maps.listeners.dca.vector: + class: Netzmacht\Contao\Leaflet\Listener\Dca\VectorDcaListener + arguments: + - '@netzmacht.contao_toolkit.dca.manager' diff --git a/src/Resources/contao/dca/tl_leaflet_vector.php b/src/Resources/contao/dca/tl_leaflet_vector.php index a418e98..9429dca 100644 --- a/src/Resources/contao/dca/tl_leaflet_vector.php +++ b/src/Resources/contao/dca/tl_leaflet_vector.php @@ -44,7 +44,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array 'flag' => 1, 'panelLayout' => 'sort,filter;search,limit', 'headerFields' => array('title', 'type'), - 'child_record_callback' => Netzmacht\Contao\Leaflet\Dca\VectorCallbacks::callback('generateRow'), + 'child_record_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.vector', 'generateRow'], ), 'label' => array ( @@ -264,7 +264,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_vector']['popup'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'getPopups'), + 'options_callback' => array('Netzmacht\Contao\Leaflet\Listener\Dca\MarkerDcaListener', 'getPopups'), 'eval' => array( 'mandatory' => false, 'tl_class' => 'w50', @@ -287,7 +287,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_vector']['style'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => Netzmacht\Contao\Leaflet\Dca\VectorCallbacks::callback('getStyles'), + 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.vector', 'getStyles'], 'eval' => array( 'mandatory' => false, 'tl_class' => 'w50',