Improve the alias generator to create valid non numeric entries.

This commit is contained in:
David Molineus
2016-10-06 08:00:53 +02:00
parent 3e84260e79
commit bbd97ae47d
2 changed files with 64 additions and 1 deletions

View File

@@ -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(

View File

@@ -0,0 +1,61 @@
<?php
/**
* @package netzmacht
* @author David Molineus <david.molineus@netzmacht.de>
* @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;
}
}