function pathauto_alias_uniquify in Pathauto 7
Same name and namespace in other branches
- 6.2 pathauto.inc \pathauto_alias_uniquify()
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
$alias: A string with the alias. Can be altered by reference.
$source: A string with the path source.
$langcode: A string with a language code.
1 call to pathauto_alias_uniquify()
- pathauto_create_alias in ./
pathauto.inc - Apply patterns to create an alias.
File
- ./
pathauto.inc, line 459 - Miscellaneous functions for Pathauto.
Code
function pathauto_alias_uniquify(&$alias, $source, $langcode) {
if (!pathauto_is_alias_reserved($alias, $source, $langcode)) {
return;
}
// If the alias already exists, generate a new, hopefully unique, variant
$maxlength = min(variable_get('pathauto_max_length', 100), _pathauto_get_schema_alias_maxlength());
$separator = variable_get('pathauto_separator', '-');
$original_alias = $alias;
$i = 0;
do {
// Append an incrementing numeric suffix until we find a unique alias.
$unique_suffix = $separator . $i;
$alias = truncate_utf8($original_alias, $maxlength - drupal_strlen($unique_suffix), TRUE) . $unique_suffix;
$i++;
} while (pathauto_is_alias_reserved($alias, $source, $langcode));
}