diff --git a/module/dca/tl_leaflet_vector.php b/module/dca/tl_leaflet_vector.php index 8cf4b44..7322529 100644 --- a/module/dca/tl_leaflet_vector.php +++ b/module/dca/tl_leaflet_vector.php @@ -157,7 +157,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array 'circleMarker extends circle' => array(), ), 'metasubpalettes' => array( - 'addPopup' => array('popupContent'), + 'addPopup' => array('popup', 'popupContent'), ), 'fields' => array @@ -242,9 +242,23 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array 'exclude' => true, 'inputType' => 'checkbox', 'filter' => true, - 'eval' => array('tl_class' => 'w50', 'submitOnChange' => true), + 'eval' => array('tl_class' => 'w50 m12', 'submitOnChange' => true), 'sql' => "char(1) NOT NULL default ''" ), + 'popup' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_vector']['popup'], + 'exclude' => true, + 'inputType' => 'select', + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Marker', 'getPopups'), + 'eval' => array( + 'mandatory' => false, + 'tl_class' => 'w50', + 'chosen' => true, + 'includeBlankOption' => true, + ), + 'sql' => "int(10) unsigned NOT NULL default '0'", + ), 'popupContent' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_vector']['popupContent'], diff --git a/module/languages/en/tl_leaflet_marker.php b/module/languages/en/tl_leaflet_marker.php index 9f03d90..bd92b5e 100644 --- a/module/languages/en/tl_leaflet_marker.php +++ b/module/languages/en/tl_leaflet_marker.php @@ -36,6 +36,8 @@ $GLOBALS['TL_LANG']['tl_leaflet_marker']['alt'][0] = 'Alternative te $GLOBALS['TL_LANG']['tl_leaflet_marker']['alt'][1] = 'Text for the alt attribute of the icon image (useful for accessibility).'; $GLOBALS['TL_LANG']['tl_leaflet_marker']['addPopup'][0] = 'Add popup'; $GLOBALS['TL_LANG']['tl_leaflet_marker']['addPopup'][1] = 'Add a popup for the marker'; +$GLOBALS['TL_LANG']['tl_leaflet_marker']['popup'][0] = 'Popup'; +$GLOBALS['TL_LANG']['tl_leaflet_marker']['popup'][1] = 'Choose a popup which options should be applied.'; $GLOBALS['TL_LANG']['tl_leaflet_marker']['popupContent'][0] = 'Popup content'; $GLOBALS['TL_LANG']['tl_leaflet_marker']['popupContent'][1] = 'Content of the popup. Insert tags are replaced.'; $GLOBALS['TL_LANG']['tl_leaflet_marker']['clickable'][0] = 'Clickable'; diff --git a/module/languages/en/tl_leaflet_vector.php b/module/languages/en/tl_leaflet_vector.php index 7e789fa..c89189f 100644 --- a/module/languages/en/tl_leaflet_vector.php +++ b/module/languages/en/tl_leaflet_vector.php @@ -41,6 +41,8 @@ $GLOBALS['TL_LANG']['tl_leaflet_vector']['multiData'][0] = 'Multi data'; $GLOBALS['TL_LANG']['tl_leaflet_vector']['multiData'][1] = 'Define coordinates of each vector in a new textarea.'; $GLOBALS['TL_LANG']['tl_leaflet_vector']['addPopup'][0] = 'Add popup'; $GLOBALS['TL_LANG']['tl_leaflet_vector']['addPopup'][1] = 'Add a popup to the vector.'; +$GLOBALS['TL_LANG']['tl_leaflet_vector']['popup'][0] = 'Popup'; +$GLOBALS['TL_LANG']['tl_leaflet_vector']['popup'][1] = 'Choose a popup which options should be used.'; $GLOBALS['TL_LANG']['tl_leaflet_vector']['popupContent'][0] = 'Popup content'; $GLOBALS['TL_LANG']['tl_leaflet_vector']['popupContent'][1] = 'Content of the popup. Insert tags are replaced.'; $GLOBALS['TL_LANG']['tl_leaflet_vector']['clickable'][0] = 'Clickable'; diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php index bdc3187..3d992a0 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php @@ -15,10 +15,12 @@ use Netzmacht\Contao\Leaflet\Definition\Style; use Netzmacht\Contao\Leaflet\Filter\Filter; use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Model\PopupModel; use Netzmacht\Contao\Leaflet\Model\StyleModel; use Netzmacht\Contao\Leaflet\ServiceContainerTrait; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\HasPopup; +use Netzmacht\LeafletPHP\Definition\UI\Popup; use Netzmacht\LeafletPHP\Definition\Vector\Path; /** @@ -62,12 +64,25 @@ class AbstractVectorMapper extends AbstractTypeMapper } if ($definition instanceof HasPopup && $model->addPopup) { + $popup = null; $content = $this ->getServiceContainer() ->getFrontendValueFilter() ->filter($model->popupContent); - $definition->bindPopup($content); + if ($model->popup) { + $popupModel = PopupModel::findActiveByPK($model->popup); + + if ($popupModel) { + $popup = $mapper->handle($popupModel, $filter, null, $definition); + } + } + + if ($popup instanceof Popup) { + $definition->bindPopup($content, $popup->getOptions()); + } else { + $definition->bindPopup($content); + } } } }