3 namespace Drupal\Core\Transliteration;
5 use Drupal\Component\Transliteration\PhpTransliteration as BaseTransliteration;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
9 * Enhances PhpTransliteration with an alter hook.
11 * @ingroup transliteration
12 * @see hook_transliteration_overrides_alter()
14 class PhpTransliteration extends BaseTransliteration {
17 * The module handler to execute the transliteration_overrides alter hook.
19 * @var \Drupal\Core\Extension\ModuleHandlerInterface
21 protected $moduleHandler;
24 * Constructs a PhpTransliteration object.
26 * @param string $data_directory
27 * The directory where data files reside. If NULL, defaults to subdirectory
28 * 'data' underneath the directory where the class's PHP file resides.
29 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
30 * The module handler to execute the transliteration_overrides alter hook.
32 public function __construct($data_directory, ModuleHandlerInterface $module_handler) {
33 parent::__construct($data_directory);
35 $this->moduleHandler = $module_handler;
39 * Overrides \Drupal\Component\Transliteration\PhpTransliteration::readLanguageOverrides().
41 * Allows modules to alter the language-specific $overrides array by invoking
42 * hook_transliteration_overrides_alter().
44 protected function readLanguageOverrides($langcode) {
45 parent::readLanguageOverrides($langcode);
47 // Let modules alter the language-specific overrides.
48 $this->moduleHandler->alter('transliteration_overrides', $this->languageOverrides[$langcode], $langcode);