forked from Snck3rs/contao-leaflet-maps
Support local aliases (close #33).
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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
|
||||
(
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user