You are here

function locale_uninstall in Drupal 8

Same name and namespace in other branches
  1. 5 modules/locale/locale.install \locale_uninstall()
  2. 6 modules/locale/locale.install \locale_uninstall()
  3. 7 modules/locale/locale.install \locale_uninstall()
  4. 9 core/modules/locale/locale.install \locale_uninstall()

Implements hook_uninstall().

File

core/modules/locale/locale.install, line 29
Install, update, and uninstall functions for the Locale module.

Code

function locale_uninstall() {
  $config = \Drupal::config('locale.settings');

  // Delete all JavaScript translation files.
  $locale_js_directory = 'public://' . $config
    ->get('javascript.directory');
  if (is_dir($locale_js_directory)) {
    $locale_javascripts = \Drupal::state()
      ->get('locale.translation.javascript') ?: [];

    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = \Drupal::service('file_system');
    foreach ($locale_javascripts as $langcode => $file_suffix) {
      if (!empty($file_suffix)) {
        try {
          $file_system
            ->delete($locale_js_directory . '/' . $langcode . '_' . $file_suffix . '.js');
        } catch (FileException $e) {

          // Ignore and continue.
        }
      }
    }

    // Delete the JavaScript translations directory if empty.
    if (is_dir($locale_js_directory)) {
      if (!$file_system
        ->scanDirectory($locale_js_directory, '/.*/')) {
        $file_system
          ->rmdir($locale_js_directory);
      }
    }
  }

  // Clear variables.
  \Drupal::state()
    ->delete('system.javascript_parsed');
  \Drupal::state()
    ->delete('locale.translation.plurals');
  \Drupal::state()
    ->delete('locale.translation.javascript');
}