diff --git a/CHANGELOG.md b/CHANGELOG.md index e144574..cc6baf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ Changelog ========= +Version 1.2.0 (2017-11-13) +-------------------------- + +[Full Changelog](https://github.com/netzmacht/contao-leaflet-geocode-widget/compare/1.1.0...1.2.0) + + - Allow multiple elements + Version 1.1.0 ------------- diff --git a/composer.json b/composer.json index 61bf2d5..d3e75c3 100644 --- a/composer.json +++ b/composer.json @@ -42,8 +42,8 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev", - "dev-develop": "1.1.x-dev" + "dev-master": "1.2.x-dev", + "dev-develop": "1.3.x-dev" }, "contao-manager-plugin": "Netzmacht\\Contao\\Leaflet\\GeocodeWidget\\ContaoManager\\Plugin" } diff --git a/src/GeocodeWidget.php b/src/GeocodeWidget.php index d869b17..9665504 100644 --- a/src/GeocodeWidget.php +++ b/src/GeocodeWidget.php @@ -15,7 +15,8 @@ namespace Netzmacht\Contao\Leaflet\GeocodeWidget; /** * Class GeocodeWidget * - * @package Netzmacht\Contao\Leaflet\GeocodeWidget + * @property int size + * @property bool multiple */ class GeocodeWidget extends \Widget { @@ -87,20 +88,39 @@ class GeocodeWidget extends \Widget */ public function generate() { - $template = new \BackendTemplate($this->widgetTemplate); - $template->setData( - [ - 'widget' => $this, - 'value' => specialchars($this->value), - 'class' => $this->strClass ? ' ' . $this->strClass : '', - 'id' => $this->strId, - 'name' => $this->strName, - 'attributes' => $this->getAttributes(), - 'wizard' => $this->wizard, - 'label' => $this->strLabel - ] - ); + $wrapperClass = 'wizard'; - return $template->parse(); + if (!$this->multiple || !$this->size) { + $this->size = 1; + } else { + $wrapperClass .= ' wizard_' . $this->size; + } + + if (!is_array($this->value)) { + $this->value = [$this->value]; + } + + $buffer = ''; + + for ($index = 0; $index < $this->size; $index++) { + $template = new \BackendTemplate($this->widgetTemplate); + $template->setData( + [ + 'wrapperClass' => $wrapperClass, + 'widget' => $this, + 'value' => \StringUtil::specialchars($this->value[$index]), + 'class' => $this->strClass ? ' ' . $this->strClass : '', + 'id' => $this->strId . (($this->size > 1) ? '_' . $index : ''), + 'name' => $this->strName . (($this->size > 1) ? '[]' : ''), + 'attributes' => $this->getAttributes(), + 'wizard' => $this->wizard, + 'label' => $this->strLabel, + ] + ); + + $buffer .= $template->parse(); + } + + return $buffer; } } diff --git a/src/Resources/contao/templates/be_widget_leaflet_geocode.html5 b/src/Resources/contao/templates/be_widget_leaflet_geocode.html5 index 9bc5508..e299ab8 100644 --- a/src/Resources/contao/templates/be_widget_leaflet_geocode.html5 +++ b/src/Resources/contao/templates/be_widget_leaflet_geocode.html5 @@ -2,6 +2,7 @@ $GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet/leaflet.css'; $GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.css'; +$GLOBALS['TL_CSS'][] = 'bundles/leafletgeocodewidget/css/backend.css'; $GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/leaflet/leaflet.js'; $GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.js'; @@ -9,7 +10,7 @@ $GLOBALS['TL_JAVASCRIPT'][] = 'bundles/leafletgeocodewidget/js/geocode.widget.js ?> -
+