Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / Transliteration / PhpTransliteration.php
1 <?php
2
3 namespace Drupal\Core\Transliteration;
4
5 use Drupal\Component\Transliteration\PhpTransliteration as BaseTransliteration;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7
8 /**
9  * Enhances PhpTransliteration with an alter hook.
10  *
11  * @ingroup transliteration
12  * @see hook_transliteration_overrides_alter()
13  */
14 class PhpTransliteration extends BaseTransliteration {
15
16   /**
17    * The module handler to execute the transliteration_overrides alter hook.
18    *
19    * @var \Drupal\Core\Extension\ModuleHandlerInterface
20    */
21   protected $moduleHandler;
22
23   /**
24    * Constructs a PhpTransliteration object.
25    *
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.
31    */
32   public function __construct($data_directory, ModuleHandlerInterface $module_handler) {
33     parent::__construct($data_directory);
34
35     $this->moduleHandler = $module_handler;
36   }
37
38   /**
39    * Overrides \Drupal\Component\Transliteration\PhpTransliteration::readLanguageOverrides().
40    *
41    * Allows modules to alter the language-specific $overrides array by invoking
42    * hook_transliteration_overrides_alter().
43    */
44   protected function readLanguageOverrides($langcode) {
45     parent::readLanguageOverrides($langcode);
46
47     // Let modules alter the language-specific overrides.
48     $this->moduleHandler->alter('transliteration_overrides', $this->languageOverrides[$langcode], $langcode);
49   }
50
51 }