public function DomainAliasUniquifier::uniquify in Domain Path 8
Check to ensure a path alias is unique and add suffix variants if necessary.
Given an alias 'content/test' if a path alias with the exact alias already exists, the function will change the alias to 'content/test-0' and will increase the number suffix until it finds a unique alias.
Parameters
string $alias: A string with the alias. Can be altered by reference.
string $source: A string with the path source.
string $langcode: A string with a language code.
Overrides AliasUniquifier::uniquify
File
- modules/
domain_path_pathauto/ src/ DomainAliasUniquifier.php, line 17
Class
- DomainAliasUniquifier
- Provides a utility for creating a unique domain path alias.
Namespace
Drupal\domain_path_pathautoCode
public function uniquify(&$alias, $source, $langcode, $domain_id = '') {
$config = $this->configFactory
->get('pathauto.settings');
if (!$this
->isReserved($alias, $source, $langcode, $domain_id)) {
return;
}
// If the alias already exists, generate a new, hopefully unique, variant.
$maxlength = min($config
->get('max_length'), $this->aliasStorageHelper
->getAliasSchemaMaxlength());
$separator = $config
->get('separator');
$original_alias = $alias;
$i = 0;
do {
// Append an incrementing numeric suffix until we find a unique alias.
$unique_suffix = $separator . $i;
$alias = Unicode::truncate($original_alias, $maxlength - mb_strlen($unique_suffix), TRUE) . $unique_suffix;
$i++;
} while ($this
->isReserved($alias, $source, $langcode));
}