Last active
March 3, 2022 15:07
-
-
Save loominade/325ebb952d83fd1b6da7d03f2537eec2 to your computer and use it in GitHub Desktop.
German transliteration for IDs in Drupal 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $vars['id'] = GermanHtml::getUniqueId('Öktöberfest'); | |
// → <h1 id="oekoeberfest">Öktöberfest</h1> | |
class GermanHtml extends Drupal\Component\Utility\Html { | |
public static function getId($id) { | |
$id = str_replace([ | |
' ', | |
'_', | |
'[', | |
']', | |
'ä', | |
'ö', | |
'ü', | |
'ß', | |
], [ | |
'-', | |
'-', | |
'-', | |
'', | |
'ae', | |
'oe', | |
'ue', | |
'ss', | |
], mb_strtolower($id)); | |
$id = preg_replace('/[^a-z0-9\\-_]/', '', $id); | |
$id = preg_replace('/\\-+/', '-', $id); | |
return $id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment