Alias generator¶
Toolkit provides an flexible, configurable alias generator which is able to creates unique aliases in different formats.
Filter based alias generator¶
The core of this tool is a filter based alias generator. It implements the alias generator interface and uses a set of filters to generate the alias. It uses a validator to ensure a valid alias is generated.
Features¶
- Different alias generation strategies
- Combining multiple columns
- Customizable separator string
Provided filters¶
All provided filters have different strategies to modify an alias value. They can combine strings or just return a simple value.
- ExistingAliasFilter
- This filter just passes the existing alias value. Usually it should be the first filter in the chain. If you always want to recreate an alias just don’t use this filter.
- RawValueFilter
- This filter uses the alias values
- SlugifyFilter
- Generates a standardized value like Contao standardize helper function does.
- SuffixFilter
- This filter adds a numeric suffix which is count until an valid alias is generated.
Provided validators¶
- UniqueDatabaseValueValidator
- This validator checks the database if an unique value exists. It only has a global scope which means the unique value has to be unique in the whole data set.
Default factory¶
Toolkit has a default factory which creates an alias generator which has the default behaviour how Contao generates alias:
- Only create alias value if field is empty
- standardize the value
- Add suffix value
<?php
// Default alias generator factory is provided as service with service id:
// "netzmacht.contao_toolkit.data.alias_generator.factory.default_factory"
/** @var \Netzmacht\Contao\Toolkit\Data\Alias\Factory\AliasGeneratorFactory $factory */
$aliasGenerator = $factory->create('my_table', 'alias_field', ['value', 'fields']);