mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-29 03:24:37 +01:00
Improve the alias generator to create valid non numeric entries.
This commit is contained in:
@@ -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(
|
||||
|
||||
61
src/Netzmacht/Contao/Leaflet/Alias/DefaultAliasFilter.php
Normal file
61
src/Netzmacht/Contao/Leaflet/Alias/DefaultAliasFilter.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user