mirror of
https://github.com/netzmacht/contao-leaflet-geocode-widget.git
synced 2025-12-02 13:43:40 +01:00
Add an wizard callback listener for the radius field.
Fix readme markup. Add missing wizard class.
This commit is contained in:
22
README.md
22
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 \'\''
|
||||
];
|
||||
```
|
||||
|
||||
37
src/DependencyInjection/LeafletGeocodeWidgetExtension.php
Normal file
37
src/DependencyInjection/LeafletGeocodeWidgetExtension.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Geocode backend widget based on Leaflet.
|
||||
*
|
||||
* @package netzmacht
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @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');
|
||||
}
|
||||
}
|
||||
45
src/EventListener/RadiusWizardCallbackListener.php
Normal file
45
src/EventListener/RadiusWizardCallbackListener.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Geocode backend widget based on Leaflet.
|
||||
*
|
||||
* @package netzmacht
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @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(
|
||||
'<a href="#" onclick="$(\'ctrl_%s_toggle\').fireEvent(\'click\');return false;"><img src="%s"></a>',
|
||||
$GLOBALS['TL_DCA'][$dataContainer->table]['fields'][$dataContainer->field]['eval']['coordinates'],
|
||||
'bundles/leafletgeocodewidget/img/map.png'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\GeocodeWidget;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\GeocodeWidget as BaseWidget;
|
||||
|
||||
3
src/Resources/config/listeners.yml
Normal file
3
src/Resources/config/listeners.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
services:
|
||||
netzmacht.contao_leaflet_geocode.listeners.radius_wizard:
|
||||
class: Netzmacht\Contao\Leaflet\GeocodeWidget\EventListener\RadiusWizardCallbackListener
|
||||
Reference in New Issue
Block a user