function locale_uninstall

Same name in other branches
  1. 7.x modules/locale/locale.install \locale_uninstall()
  2. 9 core/modules/locale/locale.install \locale_uninstall()
  3. 10 core/modules/locale/locale.install \locale_uninstall()
  4. 11.x core/modules/locale/locale.install \locale_uninstall()

Implements hook_uninstall().

File

core/modules/locale/locale.install, line 29

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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.