You are here

public function AliasCleaner::cleanAlias in Pathauto 8

Clean up an URL alias.

Performs the following alterations:

  • Trim duplicate, leading, and trailing back-slashes.
  • Trim duplicate, leading, and trailing separators.
  • Shorten to a desired length and logical position based on word boundaries.

Parameters

string $alias: A string with the URL alias to clean up.

Return value

string The cleaned URL alias.

Overrides AliasCleanerInterface::cleanAlias

File

src/AliasCleaner.php, line 101

Class

AliasCleaner
Provides an alias cleaner.

Namespace

Drupal\pathauto

Code

public function cleanAlias($alias) {
  $config = $this->configFactory
    ->get('pathauto.settings');
  $alias_max_length = min($config
    ->get('max_length'), $this->aliasStorageHelper
    ->getAliasSchemaMaxLength());
  $output = $alias;

  // Trim duplicate, leading, and trailing separators. Do this before cleaning
  // backslashes since a pattern like "[token1]/[token2]-[token3]/[token4]"
  // could end up like "value1/-/value2" and if backslashes were cleaned first
  // this would result in a duplicate backslash.
  $output = $this
    ->getCleanSeparators($output);

  // Trim duplicate, leading, and trailing backslashes.
  $output = $this
    ->getCleanSeparators($output, '/');

  // Shorten to a logical place based on word boundaries.
  $output = Unicode::truncate($output, $alias_max_length, TRUE);
  return $output;
}