Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Core\Transliteration;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Transliteration\PhpTransliteration as BaseTransliteration;
|
Chris@0
|
6 use Drupal\Core\Extension\ModuleHandlerInterface;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Enhances PhpTransliteration with an alter hook.
|
Chris@0
|
10 *
|
Chris@0
|
11 * @ingroup transliteration
|
Chris@0
|
12 * @see hook_transliteration_overrides_alter()
|
Chris@0
|
13 */
|
Chris@0
|
14 class PhpTransliteration extends BaseTransliteration {
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * The module handler to execute the transliteration_overrides alter hook.
|
Chris@0
|
18 *
|
Chris@0
|
19 * @var \Drupal\Core\Extension\ModuleHandlerInterface
|
Chris@0
|
20 */
|
Chris@0
|
21 protected $moduleHandler;
|
Chris@0
|
22
|
Chris@0
|
23 /**
|
Chris@0
|
24 * Constructs a PhpTransliteration object.
|
Chris@0
|
25 *
|
Chris@0
|
26 * @param string $data_directory
|
Chris@0
|
27 * The directory where data files reside. If NULL, defaults to subdirectory
|
Chris@0
|
28 * 'data' underneath the directory where the class's PHP file resides.
|
Chris@0
|
29 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
Chris@0
|
30 * The module handler to execute the transliteration_overrides alter hook.
|
Chris@0
|
31 */
|
Chris@0
|
32 public function __construct($data_directory, ModuleHandlerInterface $module_handler) {
|
Chris@0
|
33 parent::__construct($data_directory);
|
Chris@0
|
34
|
Chris@0
|
35 $this->moduleHandler = $module_handler;
|
Chris@0
|
36 }
|
Chris@0
|
37
|
Chris@0
|
38 /**
|
Chris@0
|
39 * Overrides \Drupal\Component\Transliteration\PhpTransliteration::readLanguageOverrides().
|
Chris@0
|
40 *
|
Chris@0
|
41 * Allows modules to alter the language-specific $overrides array by invoking
|
Chris@0
|
42 * hook_transliteration_overrides_alter().
|
Chris@0
|
43 */
|
Chris@0
|
44 protected function readLanguageOverrides($langcode) {
|
Chris@0
|
45 parent::readLanguageOverrides($langcode);
|
Chris@0
|
46
|
Chris@0
|
47 // Let modules alter the language-specific overrides.
|
Chris@0
|
48 $this->moduleHandler->alter('transliteration_overrides', $this->languageOverrides[$langcode], $langcode);
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 }
|