diff --git a/module/config/services.php b/module/config/services.php index 6f94f18..48ceddf 100644 --- a/module/config/services.php +++ b/module/config/services.php @@ -170,6 +170,33 @@ $container[LeafletServices::ALIAS_GENERATOR] = $container->share( } ); +/** + * Leaflet alias generator. + * + * @return \Netzmacht\Contao\Toolkit\Data\Alias\AliasGenerator + */ +$container[LeafletServices::PARENT_ALIAS_GENERATOR] = $container->share( + function ($container) { + return function ($dataContainerName, $aliasField, $fields) use ($container) { + $filters = [ + new ExistingAliasFilter(), + new SlugifyFilter($fields), + new DefaultAliasFilter($dataContainerName), + new SuffixFilter(), + ]; + + $validator = new UniqueDatabaseValueValidator( + $container[Services::DATABASE_CONNECTION], + $dataContainerName, + $aliasField, + ['pid'] + ); + + return new FilterBasedAliasGenerator($filters, $validator, $dataContainerName, $aliasField, '_'); + }; + } +); + /** * Callback helper class for tl_leaflet_map. * diff --git a/module/dca/tl_leaflet_control.php b/module/dca/tl_leaflet_control.php index 0f2655d..9ee11ba 100644 --- a/module/dca/tl_leaflet_control.php +++ b/module/dca/tl_leaflet_control.php @@ -22,7 +22,6 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array ( 'id' => 'primary', 'pid' => 'index', - 'alias' => 'unique', ) ) ), @@ -167,12 +166,12 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array 'tl_leaflet_control', 'alias', ['title'], - \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR + \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::PARENT_ALIAS_GENERATOR ), \Netzmacht\Contao\Leaflet\Dca\Validator::callback('validateAlias'), ), - 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), - 'sql' => "varchar(255) NOT NULL default ''" + 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'nullIfEmpty' => true), + 'sql' => "varchar(255) NULL" ), 'type' => array ( diff --git a/src/Netzmacht/Contao/Leaflet/DependencyInjection/LeafletServices.php b/src/Netzmacht/Contao/Leaflet/DependencyInjection/LeafletServices.php index a08229a..cd2cec3 100644 --- a/src/Netzmacht/Contao/Leaflet/DependencyInjection/LeafletServices.php +++ b/src/Netzmacht/Contao/Leaflet/DependencyInjection/LeafletServices.php @@ -31,7 +31,7 @@ class LeafletServices * * @return AliasGenerator */ - const ALIAS_GENERATOR = 'leaflet.alias-generator'; + const ALIAS_GENERATOR = 'leaflet.alias-generator.default'; /** * Service name of the boot handler. @@ -88,4 +88,11 @@ class LeafletServices * @return ValueFilter */ const FRONTEND_VALUE_FILTER = 'leaflet.frontend.value-filter'; + + /** + * Service name for the alias generator uses for rows being unique in the pid. + * + * @return AliasGenerator + */ + const PARENT_ALIAS_GENERATOR = 'leaflet.alias-generator.parent'; }