Add popup support for vectors.

This commit is contained in:
David Molineus
2015-01-27 18:17:05 +01:00
parent 3abe5c6517
commit 39f8e8d491
4 changed files with 36 additions and 3 deletions

View File

@@ -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'],

View File

@@ -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';

View File

@@ -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';

View File

@@ -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);
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);
}
}
}
}