PhpTransliteration.php 1.6 KB

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