diff --git a/module/config/services.php b/module/config/services.php index 3a29c6c..10897a9 100644 --- a/module/config/services.php +++ b/module/config/services.php @@ -10,6 +10,7 @@ */ use Interop\Container\ContainerInterface; +use Netzmacht\Contao\Leaflet\Alias\DefaultAliasFilter; use Netzmacht\Contao\Leaflet\Boot; use Netzmacht\Contao\Leaflet\ContaoAssets; use Netzmacht\Contao\Leaflet\Dca\ControlCallbacks; @@ -138,7 +139,8 @@ $container[LeafletServices::ALIAS_GENERATOR] = $container->share( $filters = [ new ExistingAliasFilter(), new SlugifyFilter($fields), - new SuffixFilter(false), + new DefaultAliasFilter($dataContainerName), + new SuffixFilter(), ]; $validator = new UniqueDatabaseValueValidator( diff --git a/src/Netzmacht/Contao/Leaflet/Alias/DefaultAliasFilter.php b/src/Netzmacht/Contao/Leaflet/Alias/DefaultAliasFilter.php new file mode 100644 index 0000000..3fe9e70 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Alias/DefaultAliasFilter.php @@ -0,0 +1,61 @@ + + * @copyright 2016 netzmacht David Molineus. All rights reserved. + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Alias; + +use Netzmacht\Contao\Toolkit\Data\Alias\Filter\AbstractFilter; + +/** + * Class DefaultAliasFilter creates an prefix of the alias. + * + * @package Netzmacht\Contao\Leaflet\Alias + */ +class DefaultAliasFilter extends AbstractFilter +{ + /** + * Alias prefix. + * + * @var string + */ + private $prefix; + + /** + * DefaultAliasFilter constructor. + * + * @param string $dataContainerName Data container name. + * @param int $combine Combine strategy. + */ + public function __construct($dataContainerName, $combine = self::COMBINE_REPLACE) + { + parent::__construct(true, $combine); + + $this->prefix = str_replace('tl_leaflet_', '', $dataContainerName); + } + + /** + * {@inheritdoc} + */ + public function repeatUntilValid() + { + return false; + } + + /** + * {@inheritdoc} + */ + public function apply($model, $value, $separator) + { + if (!$value) { + return $this->prefix . $separator . $model->id; + } + + return $value; + } +}