diff --git a/module/config/services.php b/module/config/services.php index 8f23f41..f732369 100644 --- a/module/config/services.php +++ b/module/config/services.php @@ -9,12 +9,18 @@ * */ +use Netzmacht\Contao\Leaflet\Alias\UnderscoreFilter; use Netzmacht\Contao\Leaflet\Boot; use Netzmacht\Contao\Leaflet\ContaoAssets; use Netzmacht\Contao\Leaflet\Frontend\ValueFilter; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\MapService; use Netzmacht\Contao\Leaflet\ServiceContainer; +use Netzmacht\Contao\Toolkit\Data\Alias\Filter\ExistingAliasFilter; +use Netzmacht\Contao\Toolkit\Data\Alias\Filter\SlugifyFilter; +use Netzmacht\Contao\Toolkit\Data\Alias\Filter\SuffixFilter; +use Netzmacht\Contao\Toolkit\Data\Alias\FilterBasedAliasGenerator; +use Netzmacht\Contao\Toolkit\Data\Alias\Validator\UniqueDatabaseValueValidator; use Netzmacht\Contao\Toolkit\DependencyInjection\Services; use Netzmacht\JavascriptBuilder\Builder; use Netzmacht\JavascriptBuilder\Encoder\ChainEncoder; @@ -119,3 +125,58 @@ $container['leaflet.frontend.value-filter'] = $container->share(function($contai $container['leaflet.service-container'] = $container->share(function($container) { return new ServiceContainer($container); }); + + +/** + * Leaflet alias generator. + * + * @return \Netzmacht\Contao\Toolkit\Data\Alias\AliasGenerator + */ +$container['leaflet.alias-generator'] = $container->share( + function ($container) { + return function ($dataContainerName, $aliasField, $fields) use ($container) { + $filters = [ + new ExistingAliasFilter(), + new SlugifyFilter($fields), + new SuffixFilter(), + new UnderscoreFilter(false) + ]; + + $validator = new UniqueDatabaseValueValidator( + $container[Services::DATABASE_CONNECTION], + $dataContainerName, + $aliasField + ); + + return new FilterBasedAliasGenerator($filters, $validator, $dataContainerName, $aliasField); + }; + } +); + +$container['leaflet.dca.map-callbacks'] = $container->share( + function ($container) { + return new \Netzmacht\Contao\Leaflet\Dca\MapCallbacks( + $container[Services::DCA_MANAGER], + $container[Services::DATABASE_CONNECTION] + ); + } +); + +$container['leaflet.dca.layer-callbacks'] = $container->share( + function ($container) { + return new \Netzmacht\Contao\Leaflet\Dca\LayerCallbacks( + $container[Services::DCA_MANAGER], + $container[Services::DATABASE_CONNECTION], + $GLOBALS['LEAFLET_LAYERS'] + ); + } +); + +$container['leaflet.dca.control-callbacks'] = $container->share( + function ($container) { + return new \Netzmacht\Contao\Leaflet\Dca\ControlCallbacks( + $container[Services::DCA_MANAGER], + $container[Services::DATABASE_CONNECTION] + ); + } +); diff --git a/module/dca/tl_content.php b/module/dca/tl_content.php index ddf8d6c..895804d 100644 --- a/module/dca/tl_content.php +++ b/module/dca/tl_content.php @@ -70,7 +70,7 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['leaflet_template'] = array( 'label' => &$GLOBALS['TL_LANG']['tl_content']['leaflet_template'], 'inputType' => 'select', 'exclude' => true, - 'options_callback' => \Netzmacht\Contao\Toolkit\Dca::createGetTemplatesCallback('leaflet_map_js'), + 'options_callback' => \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::getTemplates('leaflet_map_js'), 'eval' => array( 'tl_class' => 'w50', 'chosen' => true, diff --git a/module/dca/tl_leaflet_control.php b/module/dca/tl_leaflet_control.php index 3bc5278..385a7b7 100644 --- a/module/dca/tl_leaflet_control.php +++ b/module/dca/tl_leaflet_control.php @@ -38,7 +38,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array 'flag' => 1, 'sorting' => 2, 'panelLayout' => 'filter,sort;search,limit', - 'child_record_callback' => array('Netzmacht\Contao\Leaflet\Dca\Control', 'generateRow'), + 'child_record_callback' => \Netzmacht\Contao\Leaflet\Dca\ControlCallbacks::callback('generateRow'), ), 'label' => array ( @@ -81,10 +81,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['toggle'], 'icon' => 'visible.gif', 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"', - 'button_callback' => \Netzmacht\Contao\Toolkit\Dca::createToggleIconCallback( - 'tl_leaflet_control', - 'active' - ) + 'button_callback' => \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::stateButton('tl_leaflet_control', 'active') ), 'show' => array ( @@ -166,7 +163,12 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array 'inputType' => 'text', 'search' => true, 'save_callback' => array( - \Netzmacht\Contao\Leaflet\Dca\Helper::createGenerateAliasCallback('tl_leaflet_control', 'title'), + \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::aliasGenerator( + 'tl_leaflet_control', + 'alias', + ['title'], + 'leaflet.alias-generator' + ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'sql' => "varchar(255) NOT NULL default ''" @@ -267,10 +269,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array 'exclude' => true, 'inputType' => 'multiColumnWizard', 'load_callback' => array( - array('Netzmacht\Contao\Leaflet\Dca\Control', 'loadLayerRelations'), + \Netzmacht\Contao\Leaflet\Dca\ControlCallbacks::callback('loadLayerRelations'), ), 'save_callback' => array( - array('Netzmacht\Contao\Leaflet\Dca\Control', 'saveLayerRelations'), + \Netzmacht\Contao\Leaflet\Dca\ControlCallbacks::callback('saveLayerRelations'), ), 'eval' => array ( @@ -282,7 +284,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['layer'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getLayers'), + 'options_callback' => \Netzmacht\Contao\Leaflet\Dca\ControlCallbacks::callback('getLayers'), 'eval' => array( 'style' => 'width: 300px', 'chosen' => true, @@ -369,7 +371,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomControl'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Control', 'getZoomControls'), + 'options_callback' => \Netzmacht\Contao\Leaflet\Dca\ControlCallbacks::callback('getZoomControls'), 'reference' => &$GLOBALS['TL_LANG']['tl_leaflet_control'], 'eval' => array( 'mandatory' => false, diff --git a/module/dca/tl_leaflet_icon.php b/module/dca/tl_leaflet_icon.php index 677888b..260f7d1 100644 --- a/module/dca/tl_leaflet_icon.php +++ b/module/dca/tl_leaflet_icon.php @@ -96,7 +96,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['toggle'], 'icon' => 'visible.gif', 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"', - 'button_callback' => \Netzmacht\Contao\Toolkit\Dca::createToggleIconCallback( + 'button_callback' => \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::stateButton( 'tl_leaflet_icon', 'active' ) @@ -174,7 +174,12 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array 'exclude' => true, 'inputType' => 'text', 'save_callback' => array( - \Netzmacht\Contao\Leaflet\Dca\Helper::createGenerateAliasCallback('tl_leaflet_icon', 'title'), + \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::aliasGenerator( + 'tl_leaflet_icon', + 'alias', + ['title'], + 'leaflet.alias-generator' + ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'sql' => "varchar(255) NOT NULL default ''" @@ -265,7 +270,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array 'exclude' => true, 'inputType' => 'text', 'save_callback' => array( - array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate') + array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'validateCoordinate') ), 'eval' => array( 'maxlength' => 255, @@ -280,7 +285,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array 'exclude' => true, 'inputType' => 'text', 'save_callback' => array( - array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate') + array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'validateCoordinate') ), 'eval' => array( 'maxlength' => 255, @@ -295,7 +300,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array 'exclude' => true, 'inputType' => 'text', 'save_callback' => array( - array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate') + array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'validateCoordinate') ), 'eval' => array( 'maxlength' => 255, diff --git a/module/dca/tl_leaflet_layer.php b/module/dca/tl_leaflet_layer.php index ed526fd..0c60e14 100644 --- a/module/dca/tl_leaflet_layer.php +++ b/module/dca/tl_leaflet_layer.php @@ -16,7 +16,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'enableVersioning' => true, 'ctable' => array('tl_leaflet_vector', 'tl_leaflet_marker'), 'ondelete_callback' => array( - array('Netzmacht\Contao\Leaflet\Dca\Layer', 'deleteRelations'), + \Netzmacht\Contao\Leaflet\Dca\LayerCallbacks::callback('deleteRelations'), ), 'sql' => array ( @@ -42,13 +42,13 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'flag' => 1, 'icon' => 'system/modules/leaflet/assets/img/layers.png', 'panelLayout' => 'filter;search,limit', - 'paste_button_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getPasteButtons'), + 'paste_button_callback' => \Netzmacht\Contao\Leaflet\Dca\LayerCallbacks::callback('getPasteButtons'), ), 'label' => array ( 'fields' => array('title'), 'format' => '%s', - 'label_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'generateRow') + 'label_callback' => \Netzmacht\Contao\Leaflet\Dca\LayerCallbacks::callback('generateRow') ), 'global_operations' => array ( @@ -88,14 +88,14 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['markers'], 'href' => 'table=tl_leaflet_marker', 'icon' => 'edit.gif', - 'button_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'generateMarkersButton'), + 'button_callback' => \Netzmacht\Contao\Leaflet\Dca\LayerCallbacks::callback('generateMarkersButton') ), 'vectors' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['vectors'], 'href' => 'table=tl_leaflet_vector', 'icon' => 'edit.gif', - 'button_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'generateVectorsButton'), + 'button_callback' => \Netzmacht\Contao\Leaflet\Dca\LayerCallbacks::callback('generateVectorsButton'), ), 'edit' => array ( @@ -128,10 +128,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['toggle'], 'icon' => 'visible.gif', 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"', - 'button_callback' => \Netzmacht\Contao\Toolkit\Dca::createToggleIconCallback( + 'button_callback' => \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::stateButton( 'tl_leaflet_layer', 'active' - ) + ), ), 'show' => array ( @@ -261,7 +261,12 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'inputType' => 'text', 'search' => true, 'save_callback' => array( - \Netzmacht\Contao\Leaflet\Dca\Helper::createGenerateAliasCallback('tl_leaflet_layer', 'title'), + \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::aliasGenerator( + 'tl_leaflet_layer', + 'alias', + ['title'], + 'leaflet.alias-generator' + ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'sql' => "varchar(255) NOT NULL default ''" @@ -317,7 +322,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'submitOnChange' => true, 'chosen' => false, ), - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getVariants'), + 'options_callback' => \Netzmacht\Contao\Leaflet\Dca\LayerCallbacks::callback('getVariants'), 'sql' => "varchar(32) NOT NULL default ''" ), 'tile_provider_key' => array @@ -366,7 +371,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['reference'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getLayers'), + 'options_callback' => \Netzmacht\Contao\Leaflet\Dca\LayerCallbacks::callback('getLayers'), 'eval' => array( 'mandatory' => true, 'tl_class' => 'w50', @@ -462,7 +467,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['disableClusteringAtZoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getZoomLevels'), + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'), 'default' => '', 'eval' => array( 'maxlength' => 4, @@ -542,7 +547,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['boundsMode'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getBoundsModes'), + 'options_callback' => \Netzmacht\Contao\Leaflet\Dca\LayerCallbacks::callback('getBoundsModes'), 'eval' => array('tl_class' => 'w50', 'includeBlankOption' => true), 'sql' => "varchar(6) NOT NULL default ''" ), diff --git a/module/dca/tl_leaflet_map.php b/module/dca/tl_leaflet_map.php index 11430aa..e03fdd8 100644 --- a/module/dca/tl_leaflet_map.php +++ b/module/dca/tl_leaflet_map.php @@ -163,7 +163,12 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'inputType' => 'text', 'search' => true, 'save_callback' => array( - \Netzmacht\Contao\Leaflet\Dca\Helper::createGenerateAliasCallback('tl_leaflet_map', 'title'), + \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::aliasGenerator( + 'tl_leaflet_map', + 'alias', + ['title'], + 'leaflet.alias-generator' + ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'sql' => "varchar(255) NOT NULL default ''" @@ -174,10 +179,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'exclude' => true, 'inputType' => 'text', 'save_callback' => array( - array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate') + array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'validateCoordinate') ), 'wizard' => array( - array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getGeocoder') + array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getGeocoder') ), 'eval' => array( 'maxlength' => 255, @@ -192,10 +197,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'exclude' => true, 'inputType' => 'multiColumnWizard', 'load_callback' => array( - array('Netzmacht\Contao\Leaflet\Dca\Map', 'loadLayerRelations'), + \Netzmacht\Contao\Leaflet\Dca\MapCallbacks::callback('loadLayerRelations'), ), 'save_callback' => array( - array('Netzmacht\Contao\Leaflet\Dca\Map', 'saveLayerRelations'), + \Netzmacht\Contao\Leaflet\Dca\MapCallbacks::callback('saveLayerRelations'), ), 'eval' => array( 'multiple' => true, @@ -206,7 +211,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['reference'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getLayers'), + 'options_callback' => \Netzmacht\Contao\Leaflet\Dca\MapCallbacks::callback('getLayers'), 'eval' => array( 'mandatory' => true, 'tl_class' => 'w50', @@ -226,7 +231,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['zoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getZoomLevels'), + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'), 'default' => '', 'eval' => array( 'maxlength' => 4, @@ -251,7 +256,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['minZoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getZoomLevels'), + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'), 'eval' => array( 'maxlength' => 4, 'rgxp' => 'digit', @@ -266,7 +271,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['maxZoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getZoomLevels'), + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'), 'eval' => array( 'maxlength' => 4, 'rgxp' => 'digit', @@ -497,7 +502,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['locateMaxZoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getZoomLevels'), + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'), 'eval' => array( 'maxlength' => 4, 'rgxp' => 'digit', diff --git a/module/dca/tl_leaflet_marker.php b/module/dca/tl_leaflet_marker.php index beab48d..26b413d 100644 --- a/module/dca/tl_leaflet_marker.php +++ b/module/dca/tl_leaflet_marker.php @@ -40,7 +40,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array 'flag' => 1, 'panelLayout' => 'sort,filter;search,limit', 'headerFields' => array('title', 'type'), - 'child_record_callback' => array('Netzmacht\Contao\Leaflet\Dca\Marker', 'generateRow'), + 'child_record_callback' => array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'generateRow'), ), 'label' => array ( @@ -97,7 +97,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['toggle'], 'icon' => 'visible.gif', 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"', - 'button_callback' => \Netzmacht\Contao\Toolkit\Dca::createToggleIconCallback( + 'button_callback' => \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::stateButton( 'tl_leaflet_marker', 'active' ) @@ -172,7 +172,12 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array 'inputType' => 'text', 'search' => true, 'save_callback' => array( - \Netzmacht\Contao\Leaflet\Dca\Helper::createGenerateAliasCallback('tl_leaflet_marker', 'title'), + \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::aliasGenerator( + 'tl_leaflet_marker', + 'alias', + ['title'], + 'leaflet.alias-generator' + ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'sql' => "varchar(255) NOT NULL default ''" @@ -183,14 +188,14 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array 'exclude' => true, 'inputType' => 'text', 'save_callback' => array( - array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate'), - array('Netzmacht\Contao\Leaflet\Dca\Marker', 'saveCoordinates') + array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'validateCoordinate'), + array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'saveCoordinates') ), 'load_callback' => array( - array('Netzmacht\Contao\Leaflet\Dca\Marker', 'loadCoordinates') + array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'loadCoordinates') ), 'wizard' => array( - array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getGeocoder') + array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getGeocoder') ), 'eval' => array( 'maxlength' => 255, @@ -264,7 +269,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['popup'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Marker', 'getPopups'), + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'getPopups'), 'eval' => array( 'mandatory' => false, 'tl_class' => 'w50', @@ -295,7 +300,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['icon'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Marker', 'getIcons'), + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'getIcons'), 'eval' => array( 'mandatory' => true, 'tl_class' => 'w50', diff --git a/module/dca/tl_leaflet_popup.php b/module/dca/tl_leaflet_popup.php index d6e35aa..1d62e9e 100644 --- a/module/dca/tl_leaflet_popup.php +++ b/module/dca/tl_leaflet_popup.php @@ -96,7 +96,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_popup'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['toggle'], 'icon' => 'visible.gif', 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"', - 'button_callback' => \Netzmacht\Contao\Toolkit\Dca::createToggleIconCallback( + 'button_callback' => \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::stateButton( 'tl_leaflet_popup', 'active' ) @@ -160,7 +160,12 @@ $GLOBALS['TL_DCA']['tl_leaflet_popup'] = array 'exclude' => true, 'inputType' => 'text', 'save_callback' => array( - \Netzmacht\Contao\Leaflet\Dca\Helper::createGenerateAliasCallback('tl_leaflet_popup', 'title'), + \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::aliasGenerator( + 'tl_leaflet_popup', + 'alias', + ['title'], + 'leaflet.alias-generator' + ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'sql' => "varchar(255) NOT NULL default ''" @@ -225,7 +230,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_popup'] = array 'exclude' => true, 'inputType' => 'text', 'save_callback' => array( - array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate') + array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'validateCoordinate') ), 'eval' => array( 'maxlength' => 255, diff --git a/module/dca/tl_leaflet_style.php b/module/dca/tl_leaflet_style.php index f3ea5d9..1d68f46 100644 --- a/module/dca/tl_leaflet_style.php +++ b/module/dca/tl_leaflet_style.php @@ -95,7 +95,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_style'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_style']['toggle'], 'icon' => 'visible.gif', 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"', - 'button_callback' => \Netzmacht\Contao\Toolkit\Dca::createToggleIconCallback( + 'button_callback' => \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::stateButton( 'tl_leaflet_style', 'active' ) @@ -153,7 +153,12 @@ $GLOBALS['TL_DCA']['tl_leaflet_style'] = array 'exclude' => true, 'inputType' => 'text', 'save_callback' => array( - \Netzmacht\Contao\Leaflet\Dca\Helper::createGenerateAliasCallback('tl_leaflet_style', 'title'), + \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::aliasGenerator( + 'tl_leaflet_style', + 'alias', + ['title'], + 'leaflet.alias-generator' + ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'sql' => "varchar(255) NOT NULL default ''" @@ -189,7 +194,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_style'] = array 'exclude' => true, 'inputType' => 'text', 'wizard' => array( - \Netzmacht\Contao\Toolkit\Dca::createColorPickerCallback(), + \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::colorPicker() ), 'eval' => array( 'tl_class' => 'w50 wizard clr', @@ -230,7 +235,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_style'] = array 'exclude' => true, 'inputType' => 'text', 'wizard' => array( - \Netzmacht\Contao\Toolkit\Dca::createColorPickerCallback(), + \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::colorPicker() ), 'eval' => array( 'tl_class' => 'clr w50 wizard', diff --git a/module/dca/tl_leaflet_vector.php b/module/dca/tl_leaflet_vector.php index dcf6d4a..ded43a2 100644 --- a/module/dca/tl_leaflet_vector.php +++ b/module/dca/tl_leaflet_vector.php @@ -104,7 +104,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_vector']['toggle'], 'icon' => 'visible.gif', 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"', - 'button_callback' => \Netzmacht\Contao\Toolkit\Dca::createToggleIconCallback( + 'button_callback' => \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::stateButton( 'tl_leaflet_vector', 'active' ) @@ -198,7 +198,12 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array 'inputType' => 'text', 'search' => true, 'save_callback' => array( - \Netzmacht\Contao\Leaflet\Dca\Helper::createGenerateAliasCallback('tl_leaflet_vector', 'title'), + \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::aliasGenerator( + 'tl_leaflet_vector', + 'alias', + ['title'], + 'leaflet.alias-generator' + ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'sql' => "varchar(255) NOT NULL default ''" diff --git a/module/dca/tl_module.php b/module/dca/tl_module.php index 3b64b03..3f5d0b5 100644 --- a/module/dca/tl_module.php +++ b/module/dca/tl_module.php @@ -70,7 +70,7 @@ $GLOBALS['TL_DCA']['tl_module']['fields']['leaflet_template'] = array( 'label' => &$GLOBALS['TL_LANG']['tl_module']['leaflet_template'], 'inputType' => 'select', 'exclude' => true, - 'options_callback' => \Netzmacht\Contao\Toolkit\Dca::createGetTemplatesCallback('leaflet_map_js'), + 'options_callback' => \Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory::getTemplates('leaflet_map_js'), 'eval' => array( 'tl_class' => 'w50', 'chosen' => true, diff --git a/src/Netzmacht/Contao/Leaflet/Alias/UnderscoreFilter.php b/src/Netzmacht/Contao/Leaflet/Alias/UnderscoreFilter.php new file mode 100644 index 0000000..9738c1d --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Alias/UnderscoreFilter.php @@ -0,0 +1,37 @@ + + * @copyright 2016 netzmacht David Molineus. All rights reserved. + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Alias; + +use Netzmacht\Contao\Toolkit\Data\Alias\Filter; + +/** + * Class UnderscoreFilter + * + * @package Netzmacht\Contao\Leaflet\Alias + */ +class UnderscoreFilter extends Filter\AbstractFilter +{ + /** + * {@inheritDoc} + */ + public function repeatUntilValid() + { + return false; + } + + /** + * {@inheritDoc} + */ + public function apply($model, $value, $separator) + { + return str_replace('-', '_', $value); + } +} diff --git a/src/Netzmacht/Contao/Leaflet/Dca/Control.php b/src/Netzmacht/Contao/Leaflet/Dca/ControlCallbacks.php similarity index 85% rename from src/Netzmacht/Contao/Leaflet/Dca/Control.php rename to src/Netzmacht/Contao/Leaflet/Dca/ControlCallbacks.php index 28da0b3..34acbd7 100644 --- a/src/Netzmacht/Contao/Leaflet/Dca/Control.php +++ b/src/Netzmacht/Contao/Leaflet/Dca/ControlCallbacks.php @@ -11,8 +11,9 @@ namespace Netzmacht\Contao\Leaflet\Dca; +use Netzmacht\Contao\Toolkit\Dca\Callback\Callbacks; +use Netzmacht\Contao\Toolkit\Dca\Manager; use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder; -use Netzmacht\Contao\Toolkit\ServiceContainerTrait; use Netzmacht\Contao\Leaflet\Model\ControlModel; use Netzmacht\Contao\Leaflet\Model\LayerModel; @@ -21,9 +22,21 @@ use Netzmacht\Contao\Leaflet\Model\LayerModel; * * @package Netzmacht\Contao\Leaflet\Dca */ -class Control +class ControlCallbacks extends Callbacks { - use ServiceContainerTrait; + /** + * Name of the data container. + * + * @var string + */ + protected static $name = 'tl_leaflet_control'; + + /** + * Helper service name. + * + * @var string + */ + protected static $serviceName = 'leaflet.dca.control-callbacks'; /** * The database connection. @@ -34,10 +47,15 @@ class Control /** * Construct. + * + * @param Manager $manager Data container manager. + * @param \Database $database Database connection. */ - public function __construct() + public function __construct(Manager $manager, \Database $database) { - $this->database = static::getServiceContainer()->getDatabaseConnection(); + parent::__construct($manager); + + $this->database = $database; } /** @@ -84,7 +102,7 @@ class Control { $collection = ControlModel::findBy('type', 'zoom', array('order' => 'title')); - return OptionsBuilder::fromCollection($collection, 'id', 'title')->getOptions(); + return OptionsBuilder::fromCollection($collection, 'title')->getOptions(); } /** diff --git a/src/Netzmacht/Contao/Leaflet/Dca/FrontendIntegration.php b/src/Netzmacht/Contao/Leaflet/Dca/FrontendIntegration.php index 1bf1ded..c69288f 100644 --- a/src/Netzmacht/Contao/Leaflet/Dca/FrontendIntegration.php +++ b/src/Netzmacht/Contao/Leaflet/Dca/FrontendIntegration.php @@ -30,7 +30,7 @@ class FrontendIntegration { $collection = MapModel::findAll(); - return OptionsBuilder::fromCollection($collection, 'id', 'title')->getOptions(); + return OptionsBuilder::fromCollection($collection, 'title')->getOptions(); } /** diff --git a/src/Netzmacht/Contao/Leaflet/Dca/Helper.php b/src/Netzmacht/Contao/Leaflet/Dca/Helper.php deleted file mode 100644 index 5d933e4..0000000 --- a/src/Netzmacht/Contao/Leaflet/Dca/Helper.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @copyright 2015 netzmacht creative David Molineus - * @license LGPL 3.0 - * @filesource - * - */ - -namespace Netzmacht\Contao\Leaflet\Dca; - -use Netzmacht\Contao\Toolkit\Dca; -use Netzmacht\Contao\Toolkit\Dca\Callback\GenerateAliasCallback; - -/** - * Helper class for dca functions. - * - * @package Netzmacht\Contao\Leaflet\Dca - */ -class Helper -{ - /** - * Generate an alias callback which creates a valid javascript var name. - * - * @param string $table The table. - * @param string $column The value column. - * - * @return GenerateAliasCallback - */ - public static function createGenerateAliasCallback($table, $column) - { - $callback = Dca::createGenerateAliasCallback($table, $column); - $callback->getGenerator()->addFilter( - function ($value) { - return str_replace('-', '_', $value); - } - ); - - return $callback; - } -} diff --git a/src/Netzmacht/Contao/Leaflet/Dca/Layer.php b/src/Netzmacht/Contao/Leaflet/Dca/LayerCallbacks.php similarity index 92% rename from src/Netzmacht/Contao/Leaflet/Dca/Layer.php rename to src/Netzmacht/Contao/Leaflet/Dca/LayerCallbacks.php index 0ce8782..9372bc7 100644 --- a/src/Netzmacht/Contao/Leaflet/Dca/Layer.php +++ b/src/Netzmacht/Contao/Leaflet/Dca/LayerCallbacks.php @@ -11,8 +11,9 @@ namespace Netzmacht\Contao\Leaflet\Dca; +use Netzmacht\Contao\Toolkit\Dca\Callback\Callbacks; +use Netzmacht\Contao\Toolkit\Dca\Manager; use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder; -use Netzmacht\Contao\Toolkit\ServiceContainerTrait; use Netzmacht\Contao\Leaflet\Model\LayerModel; /** @@ -20,9 +21,21 @@ use Netzmacht\Contao\Leaflet\Model\LayerModel; * * @package Netzmacht\Contao\Leaflet\Dca */ -class Layer +class LayerCallbacks extends Callbacks { - use ServiceContainerTrait; + /** + * Name of the data container. + * + * @var string + */ + protected static $name = 'tl_leaflet_layer'; + + /** + * Helper service name. + * + * @var string + */ + protected static $serviceName = 'leaflet.dca.layer-callbacks'; /** * Layers definition. @@ -41,12 +54,18 @@ class Layer /** * Construct. * + * @param Manager $manager Data container manager. + * @param \Database $database Database connection. + * @param array $layers Leaflet layer configuration. + * * @SuppressWarnings(PHPMD.Superglobals) */ - public function __construct() + public function __construct(Manager $manager, \Database $database, array $layers) { - $this->layers = &$GLOBALS['LEAFLET_LAYERS']; - $this->database = static::getServiceContainer()->getDatabaseConnection(); + parent::__construct($manager); + + $this->layers = $layers; + $this->database = $database; \Controller::loadLanguageFile('leaflet_layer'); @@ -237,22 +256,6 @@ class Layer return $this->generateButton($row, $href, $label, $title, $icon, $attributes); } - /** - * Get all layers except of the current layer. - * - * @param \DataContainer $dataContainer The dataContainer driver. - * - * @return array - */ - public function getLayers($dataContainer) - { - $collection = LayerModel::findBy('id !', $dataContainer->id); - - return OptionsBuilder::fromCollection($collection, 'id', 'title') - ->asTree() - ->getOptions(); - } - /** * Delete the relations when the layer is deleted. * diff --git a/src/Netzmacht/Contao/Leaflet/Dca/Leaflet.php b/src/Netzmacht/Contao/Leaflet/Dca/LeafletCallbacks.php similarity index 98% rename from src/Netzmacht/Contao/Leaflet/Dca/Leaflet.php rename to src/Netzmacht/Contao/Leaflet/Dca/LeafletCallbacks.php index 730ffc1..b112d46 100644 --- a/src/Netzmacht/Contao/Leaflet/Dca/Leaflet.php +++ b/src/Netzmacht/Contao/Leaflet/Dca/LeafletCallbacks.php @@ -22,7 +22,7 @@ use Netzmacht\LeafletPHP\Value\LatLng; * * @package Netzmacht\Contao\Leaflet\Dca */ -class Leaflet +class LeafletCallbacks { /** * Validate a coordinate. diff --git a/src/Netzmacht/Contao/Leaflet/Dca/Map.php b/src/Netzmacht/Contao/Leaflet/Dca/MapCallbacks.php similarity index 72% rename from src/Netzmacht/Contao/Leaflet/Dca/Map.php rename to src/Netzmacht/Contao/Leaflet/Dca/MapCallbacks.php index 83ab048..215bfb7 100644 --- a/src/Netzmacht/Contao/Leaflet/Dca/Map.php +++ b/src/Netzmacht/Contao/Leaflet/Dca/MapCallbacks.php @@ -11,16 +11,31 @@ namespace Netzmacht\Contao\Leaflet\Dca; -use Netzmacht\Contao\Toolkit\ServiceContainerTrait; +use Netzmacht\Contao\Leaflet\Model\LayerModel; +use Netzmacht\Contao\Toolkit\Dca\Callback\Callbacks; +use Netzmacht\Contao\Toolkit\Dca\Manager; +use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder; /** * Class Map is the helper class for the tl_leaflet_map dca. * * @package Netzmacht\Contao\Leaflet\Dca */ -class Map +class MapCallbacks extends Callbacks { - use ServiceContainerTrait; + /** + * Name of the data container. + * + * @var string + */ + protected static $name = 'tl_leaflet_map'; + + /** + * Helper service name. + * + * @var string + */ + protected static $serviceName = 'leaflet.dca.map-callbacks'; /** * The database connection. @@ -31,10 +46,15 @@ class Map /** * Construct. + * + * @param Manager $manager Data container manager. + * @param \Database $database Database connection. */ - public function __construct() + public function __construct(Manager $manager, \Database $database) { - $this->database = static::getServiceContainer()->getDatabaseConnection(); + parent::__construct($manager); + + $this->database = $database; } /** @@ -120,4 +140,20 @@ class Map return null; } + + /** + * Get all layers except of the current layer. + * + * @param \DataContainer $dataContainer The dataContainer driver. + * + * @return array + */ + public function getLayers($dataContainer) + { + $collection = LayerModel::findBy('id !', $dataContainer->id); + + return OptionsBuilder::fromCollection($collection, 'title') + ->asTree() + ->getOptions(); + } } diff --git a/src/Netzmacht/Contao/Leaflet/Dca/Marker.php b/src/Netzmacht/Contao/Leaflet/Dca/MarkerCallbacks.php similarity index 98% rename from src/Netzmacht/Contao/Leaflet/Dca/Marker.php rename to src/Netzmacht/Contao/Leaflet/Dca/MarkerCallbacks.php index b5e697c..6df9083 100644 --- a/src/Netzmacht/Contao/Leaflet/Dca/Marker.php +++ b/src/Netzmacht/Contao/Leaflet/Dca/MarkerCallbacks.php @@ -20,7 +20,7 @@ use Netzmacht\Contao\Leaflet\Model\PopupModel; * * @package Netzmacht\Contao\Leaflet\Dca */ -class Marker +class MarkerCallbacks { /** * Generate the row label. @@ -44,7 +44,6 @@ class Marker $collection = IconModel::findAll(array('order' => 'title')); $builder = OptionsBuilder::fromCollection( $collection, - 'id', function ($model) { return sprintf('%s [%s]', $model['title'], $model['type']); } @@ -61,7 +60,7 @@ class Marker public function getPopups() { $collection = PopupModel::findAll(array('order' => 'title')); - $builder = OptionsBuilder::fromCollection($collection, 'id', 'title'); + $builder = OptionsBuilder::fromCollection($collection, 'title'); return $builder->getOptions(); } diff --git a/src/Netzmacht/Contao/Leaflet/Dca/Vector.php b/src/Netzmacht/Contao/Leaflet/Dca/VectorCallbacks.php similarity index 89% rename from src/Netzmacht/Contao/Leaflet/Dca/Vector.php rename to src/Netzmacht/Contao/Leaflet/Dca/VectorCallbacks.php index adeb619..d128cff 100644 --- a/src/Netzmacht/Contao/Leaflet/Dca/Vector.php +++ b/src/Netzmacht/Contao/Leaflet/Dca/VectorCallbacks.php @@ -19,7 +19,7 @@ use Netzmacht\Contao\Leaflet\Model\StyleModel; * * @package Netzmacht\Contao\Leaflet\Dca */ -class Vector +class VectorCallbacks { /** * Generate the row label. @@ -42,6 +42,6 @@ class Vector { $collection = StyleModel::findAll(array('order' => 'title')); - return OptionsBuilder::fromCollection($collection, 'id', 'title')->getOptions(); + return OptionsBuilder::fromCollection($collection, 'title')->getOptions(); } } diff --git a/src/Netzmacht/Contao/Leaflet/Subscriber/GeoJsonSubscriber.php b/src/Netzmacht/Contao/Leaflet/Subscriber/GeoJsonSubscriber.php index 03f5b78..c16d0dd 100644 --- a/src/Netzmacht/Contao/Leaflet/Subscriber/GeoJsonSubscriber.php +++ b/src/Netzmacht/Contao/Leaflet/Subscriber/GeoJsonSubscriber.php @@ -11,7 +11,7 @@ namespace Netzmacht\Contao\Leaflet\Subscriber; -use Netzmacht\Contao\Leaflet\Dca\Vector; +use Netzmacht\Contao\Leaflet\Dca\VectorCallbacks; use Netzmacht\Contao\Leaflet\Event\ConvertToGeoJsonEvent; use Netzmacht\Contao\Leaflet\Model\LayerModel; use Netzmacht\LeafletPHP\Value\GeoJson\Feature; @@ -83,7 +83,7 @@ class GeoJsonSubscriber implements EventSubscriberInterface $definition = $event->getDefinition(); $model = $event->getModel(); - if (($definition instanceof Marker || $definition instanceof Vector) + if (($definition instanceof Marker || $definition instanceof VectorCallbacks) && $model instanceof \Model && $feature instanceof Feature) { $this->setDataProperty($model, $feature); $this->setBoundsInformation($model, $feature);