Skip to content

Instantly share code, notes, and snippets.

@loominade
Last active March 3, 2022 15:07
Show Gist options
  • Save loominade/325ebb952d83fd1b6da7d03f2537eec2 to your computer and use it in GitHub Desktop.
Save loominade/325ebb952d83fd1b6da7d03f2537eec2 to your computer and use it in GitHub Desktop.
German transliteration for IDs in Drupal 9
<?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