Commit b65a7e85 authored by DuaelFr's avatar DuaelFr Committed by Berdir
Browse files

Issue #2979476 by DuaelFr, arakwar, Berdir: Remove the punctuation before transliteration

parent b06f7b97
......@@ -231,16 +231,21 @@ class AliasCleaner implements AliasCleanerInterface {
$output = Html::decodeEntities($string);
$output = PlainTextOutput::renderFromHtml($output);
// Replace or drop punctuation based on user settings.
$output = strtr($output, $this->cleanStringCache['punctuation']);
// Optionally transliterate.
if ($this->cleanStringCache['transliterate']) {
// If the reduce strings to letters and numbers is enabled, don't bother
// replacing unknown characters with a question mark. Use an empty string
// instead.
$output = $this->transliteration->transliterate($output, $langcode, $this->cleanStringCache['reduce_ascii'] ? '' : '?');
// Replace or drop punctuation again as the transliteration process can
// convert special characters to punctuation.
$output = strtr($output, $this->cleanStringCache['punctuation']);
}
// Replace or drop punctuation based on user settings.
$output = strtr($output, $this->cleanStringCache['punctuation']);
// Reduce strings to letters and numbers.
if ($this->cleanStringCache['reduce_ascii']) {
......
name: 'Pathauto custom punctuation testing module'
type: module
core: '8.x'
description: 'Add some uncommon punctuation to the replacement list.'
package: Testing
<?php
/**
* Implements hook_pathauto_punctuation_chars_alter().
*/
function pathauto_custom_punctuation_test_pathauto_punctuation_chars_alter(array &$punctuation) {
$punctuation['copyright'] = ['value' => '©', 'name' => t('Copyright symbol')];
}
......@@ -27,7 +27,7 @@ class PathautoKernelTest extends KernelTestBase {
use PathautoTestHelperTrait;
public static $modules = ['system', 'field', 'text', 'user', 'node', 'path', 'path_alias', 'pathauto', 'taxonomy', 'token', 'filter', 'ctools', 'language'];
public static $modules = ['system', 'field', 'text', 'user', 'node', 'path', 'path_alias', 'pathauto', 'pathauto_custom_punctuation_test', 'taxonomy', 'token', 'filter', 'ctools', 'language'];
protected $currentUser;
......@@ -192,6 +192,11 @@ class PathautoKernelTest extends KernelTestBase {
// Test with default settings defined in pathauto.settings.yml.
$this->installConfig(['pathauto']);
// Add a custom setting for the copyright symbol defined in
// pathauto_custom_punctuation_test_pathauto_punctuation_chars_alter().
$this->config('pathauto.settings')->set('punctuation.copyright', PathautoGeneratorInterface::PUNCTUATION_REMOVE);
\Drupal::service('pathauto.generator')->resetCaches();
$tests = [];
......@@ -215,6 +220,9 @@ class PathautoKernelTest extends KernelTestBase {
// Transliteration.
$tests['ľščťžýáíéňô'] = 'lsctzyaieno';
// Transliteration of special chars that are converted to punctuation.
$tests['© “Drupal”'] = 'drupal';
foreach ($tests as $input => $expected) {
$output = \Drupal::service('pathauto.alias_cleaner')->cleanString($input);
$this->assertEquals($expected, $output, t("Drupal::service('pathauto.alias_cleaner')->cleanString('@input') expected '@expected', actual '@output'", [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment