From 508604111189bb9e1c89d18bc787d6753ed25b04 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Wed, 18 Jan 2017 10:56:03 +0100 Subject: [PATCH] Ongoing development. --- .gitignore | 10 ++ composer.json | 2 +- src/GeocodeWidget.php | 102 ++++++++++++++++++ src/LeafletGeocodeWidgetBundle.php | 22 ++++ src/Resources/contao/config/config.php | 11 ++ src/Resources/contao/languages/de/default.php | 11 ++ src/Resources/contao/languages/en/default.php | 11 ++ .../templates/be_widget_leaflet_geocode.html5 | 79 ++++++++++++++ 8 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 src/GeocodeWidget.php create mode 100644 src/LeafletGeocodeWidgetBundle.php create mode 100644 src/Resources/contao/config/config.php create mode 100644 src/Resources/contao/languages/de/default.php create mode 100644 src/Resources/contao/languages/en/default.php create mode 100644 src/Resources/contao/templates/be_widget_leaflet_geocode.html5 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7c9521e --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +/vendor/ +/bin/ +/demo/ +/assets/js/*.js +/node_modules/ +/.tx/ + +coverage.xml +composer.lock +npm-debug.log diff --git a/composer.json b/composer.json index bfbe7da..37fc3a4 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "php":">=5.5.0", "contao/core-bundle":"~3.5 | ~4.3", "contao-community-alliance/composer-plugin": "~2.4 | ~3.0", - "netzmacht/contao-leaflet-libraries":"~2.0" + "netzmacht/contao-leaflet-libraries":"~1.0" }, "require-dev": { "netzmacht/contao-build-tools": "~1.1" diff --git a/src/GeocodeWidget.php b/src/GeocodeWidget.php new file mode 100644 index 0000000..db83885 --- /dev/null +++ b/src/GeocodeWidget.php @@ -0,0 +1,102 @@ + + * @copyright 2017 netzmacht David Molineus. All rights reserved. + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\GeocodeWidget; + +/** + * Class GeocodeWidget + * + * @package Netzmacht\Contao\Leaflet\GeocodeWidget + */ +class GeocodeWidget extends \Widget +{ + /** + * Submit user input. + * + * @var boolean + */ + protected $blnSubmitInput = true; + + /** + * Add a for attribute. + * + * @var boolean + */ + protected $blnForAttribute = true; + + /** + * Template. + * + * @var string + */ + protected $strTemplate = 'be_widget'; + + /** + * Template name. + * + * @var string + */ + protected $widgetTemplate = 'be_widget_leaflet_geocode'; + + /** + * Validate the input. + * + * @param mixed $value Given value. + * + * @return mixed + */ + protected function validator($value) + { + $value = parent::validator($value); + + if (!$value) { + return $value; + } + + if ( + // See: http://stackoverflow.com/a/18690202 + !preg_match( + '^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)(,[-+]?\d+)?$', + $value + ) + ) { + $this->addError( + sprintf( + $GLOBALS['TL_LANG']['ERR']['leaflet_invalid_coordinate'], + $value + ) + ); + } + + return $value; + } + + /** + * Generate the widget. + * + * @return string + */ + public function generate() + { + $template = new \BackendTemplate($this->widgetTemplate); + $template->setData( + [ + 'widget' => $this, + 'value' => specialchars($this->value), + 'class' => $this->strClass ? ' ' . $this->strClass : '', + 'id' => $this->strId, + 'attributes' => $this->getAttributes(), + 'wizard' => $this->wizard, + ] + ); + + return $template->parse(); + } +} diff --git a/src/LeafletGeocodeWidgetBundle.php b/src/LeafletGeocodeWidgetBundle.php new file mode 100644 index 0000000..78db4bd --- /dev/null +++ b/src/LeafletGeocodeWidgetBundle.php @@ -0,0 +1,22 @@ + + * @copyright 2017 netzmacht David Molineus. All rights reserved. + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\GeocodeWidget; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +/** + * Class LeafletGeocodeWidgetBundle + * + * @package Netzmacht\Contao\Leaflet\GeocodeWidget + */ +class LeafletGeocodeWidgetBundle extends Bundle +{ +} diff --git a/src/Resources/contao/config/config.php b/src/Resources/contao/config/config.php new file mode 100644 index 0000000..5692e6c --- /dev/null +++ b/src/Resources/contao/config/config.php @@ -0,0 +1,11 @@ + + * @copyright 2017 netzmacht David Molineus. All rights reserved. + * @filesource + * + */ + +$GLOBALS['BE_FFL']['leaflet_geocode'] = 'Netzmacht\Contao\Leaflet\GeocodeWidget\GeocodeWidget'; diff --git a/src/Resources/contao/languages/de/default.php b/src/Resources/contao/languages/de/default.php new file mode 100644 index 0000000..656648b --- /dev/null +++ b/src/Resources/contao/languages/de/default.php @@ -0,0 +1,11 @@ + + * @copyright 2017 netzmacht David Molineus. All rights reserved. + * @filesource + * + */ + +$GLOBALS['TL_LANG']['ERR']['leaflet_invalid_coordinate'] = 'Die angegebenen Koordinaten sind ungültig.'; diff --git a/src/Resources/contao/languages/en/default.php b/src/Resources/contao/languages/en/default.php new file mode 100644 index 0000000..10a0a70 --- /dev/null +++ b/src/Resources/contao/languages/en/default.php @@ -0,0 +1,11 @@ + + * @copyright 2017 netzmacht David Molineus. All rights reserved. + * @filesource + * + */ + +$GLOBALS['TL_LANG']['ERR']['leaflet_invalid_coordinate'] = 'Invalid coordinates given.'; diff --git a/src/Resources/contao/templates/be_widget_leaflet_geocode.html5 b/src/Resources/contao/templates/be_widget_leaflet_geocode.html5 new file mode 100644 index 0000000..ac7e6e2 --- /dev/null +++ b/src/Resources/contao/templates/be_widget_leaflet_geocode.html5 @@ -0,0 +1,79 @@ + + +attributes ?> + onfocus="Backend.getScrollOffset()" +> + +
+ + +wizard ?>