From 617a996e0ea960139a81e572475516aa893c6c5b Mon Sep 17 00:00:00 2001 From: David Molineus Date: Thu, 8 Feb 2018 22:23:42 +0100 Subject: [PATCH] Add an wizard callback listener for the radius field. Fix readme markup. Add missing wizard class. --- README.md | 22 +++++++++ .../LeafletGeocodeWidgetExtension.php | 37 +++++++++++++++ .../RadiusWizardCallbackListener.php | 45 +++++++++++++++++++ src/GeocodeWidget.php | 1 - src/Resources/config/listeners.yml | 3 ++ 5 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/DependencyInjection/LeafletGeocodeWidgetExtension.php create mode 100644 src/EventListener/RadiusWizardCallbackListener.php create mode 100644 src/Resources/config/listeners.yml diff --git a/README.md b/README.md index 84b8d17..dc88089 100644 --- a/README.md +++ b/README.md @@ -94,3 +94,25 @@ $GLOBALS['TL_DCA']['tl_page']['fields']['radius'] = [ 'sql' => 'varchar(255) NOT NULL default \'\'' ]; ``` + +If you want to add an wizard icon to the radius field as well, a wizard is shipped with. You only have to add the +callback and define the coordinates field relation. + +```php +$GLOBALS['TL_DCA']['tl_page']['fields']['radius'] = [ + 'label' => ['Radius', 'Angabe des Radius in Metern'], + 'inputType' => 'text', + 'eval' => [ + 'rgxp' => 'natural', + 'default' => 500, + 'minval' => 100, + 'maxval' => 5000, + 'tl_class' => 'w50 wizard', + 'coordinates' => 'coordinates' + ], + 'wizard' => [ + ['netzmacht.contao_leaflet_geocode.listeners.radius_wizard', 'generateWizard'], + ], + 'sql' => 'varchar(255) NOT NULL default \'\'' +]; +``` diff --git a/src/DependencyInjection/LeafletGeocodeWidgetExtension.php b/src/DependencyInjection/LeafletGeocodeWidgetExtension.php new file mode 100644 index 0000000..df63e1b --- /dev/null +++ b/src/DependencyInjection/LeafletGeocodeWidgetExtension.php @@ -0,0 +1,37 @@ + + * @copyright 2016-2018 netzmacht David Molineus. All rights reserved. + * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE + * @filesource + */ + +namespace Netzmacht\Contao\Leaflet\GeocodeWidget\DependencyInjection; + +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; + +/** + * Class LeafletGeocodeWidgetExtension + */ +class LeafletGeocodeWidgetExtension extends Extension +{ + /** + * {@inheritdoc} + */ + public function load(array $configs, ContainerBuilder $container) + { + $loader = new YamlFileLoader( + $container, + new FileLocator(dirname(__DIR__) . '/Resources/config') + ); + + $loader->load('listeners.yml'); + } +} diff --git a/src/EventListener/RadiusWizardCallbackListener.php b/src/EventListener/RadiusWizardCallbackListener.php new file mode 100644 index 0000000..c046d0f --- /dev/null +++ b/src/EventListener/RadiusWizardCallbackListener.php @@ -0,0 +1,45 @@ + + * @copyright 2016-2018 netzmacht David Molineus. All rights reserved. + * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE + * @filesource + */ + +namespace Netzmacht\Contao\Leaflet\GeocodeWidget\EventListener; + +use Contao\DataContainer; + +/** + * Class RadiusWizardCallbackListener + * + * @package Netzmacht\Contao\Leaflet\GeocodeWidget\EventListener + */ +class RadiusWizardCallbackListener +{ + /** + * Generate the wizard for the radius widget. + * + * @param DataContainer $dataContainer Data container driver. + * + * @return string + * + * @SuppressWarnings(PHPMD.Superglobals) + */ + public function generateWizard($dataContainer) + { + if (!isset($GLOBALS['TL_DCA'][$dataContainer->table]['fields'][$dataContainer->field]['eval']['coordinates'])) { + return ''; + } + + return sprintf( + '', + $GLOBALS['TL_DCA'][$dataContainer->table]['fields'][$dataContainer->field]['eval']['coordinates'], + 'bundles/leafletgeocodewidget/img/map.png' + ); + } +} diff --git a/src/GeocodeWidget.php b/src/GeocodeWidget.php index 700c059..fe47724 100644 --- a/src/GeocodeWidget.php +++ b/src/GeocodeWidget.php @@ -10,7 +10,6 @@ * @filesource */ - namespace Netzmacht\Contao\Leaflet\GeocodeWidget; use Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\GeocodeWidget as BaseWidget; diff --git a/src/Resources/config/listeners.yml b/src/Resources/config/listeners.yml new file mode 100644 index 0000000..f680623 --- /dev/null +++ b/src/Resources/config/listeners.yml @@ -0,0 +1,3 @@ +services: + netzmacht.contao_leaflet_geocode.listeners.radius_wizard: + class: Netzmacht\Contao\Leaflet\GeocodeWidget\EventListener\RadiusWizardCallbackListener