diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php index b69357ef250c0014df10a9da03024c474797f870..5018efa21f48f9b31ff15b867a799b77cd2ee642 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php @@ -648,7 +648,7 @@ public function testPluralConfigStringsSourceElements() { foreach ($languages as $langcode => $data) { // Import a .po file to add a new language with a given number of plural forms - $name = tempnam('temporary://', $langcode . '_') . '.po'; + $name = \Drupal::service('file_system')->tempnam('temporary://', $langcode . '_') . '.po'; file_put_contents($name, $this->getPoFile($data['plurals'])); $this->drupalPostForm('admin/config/regional/translate/import', array( 'langcode' => $langcode, @@ -684,7 +684,7 @@ public function testPluralConfigStrings() { // First import a .po file with multiple plural forms. // This will also automatically add the 'sl' language. - $name = tempnam('temporary://', "sl_") . '.po'; + $name = \Drupal::service('file_system')->tempnam('temporary://', "sl_") . '.po'; file_put_contents($name, $this->getPoFile(4)); $this->drupalPostForm('admin/config/regional/translate/import', array( 'langcode' => 'sl', diff --git a/core/modules/locale/src/Form/ExportForm.php b/core/modules/locale/src/Form/ExportForm.php index 4a4695b5c2465748420bad42af1a4f54517032fa..47a3aeab129b034ca623af26eed1a026362dbc54 100644 --- a/core/modules/locale/src/Form/ExportForm.php +++ b/core/modules/locale/src/Form/ExportForm.php @@ -3,6 +3,7 @@ namespace Drupal\locale\Form; use Drupal\Component\Gettext\PoStreamWriter; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -23,14 +24,24 @@ class ExportForm extends FormBase { */ protected $languageManager; + /** + * The file system service. + * + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + /** * Constructs a new ExportForm. * * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * The file system service. */ - public function __construct(LanguageManagerInterface $language_manager) { + public function __construct(LanguageManagerInterface $language_manager, FileSystemInterface $file_system) { $this->languageManager = $language_manager; + $this->fileSystem = $file_system; } /** @@ -38,7 +49,8 @@ public function __construct(LanguageManagerInterface $language_manager) { */ public static function create(ContainerInterface $container) { return new static( - $container->get('language_manager') + $container->get('language_manager'), + $container->get('file_system') ); } @@ -147,7 +159,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $item = $reader->readItem(); if (!empty($item)) { - $uri = tempnam('temporary://', 'po_'); + $uri = $this->fileSystem->tempnam('temporary://', 'po_'); $header = $reader->getHeader(); $header->setProjectName($this->config('system.site')->get('name')); $header->setLanguageName($language_name); diff --git a/core/modules/locale/src/Tests/LocaleExportTest.php b/core/modules/locale/src/Tests/LocaleExportTest.php index 3d861de15f8f5b9979c3cc8b2862d63f71811c6c..f9cd2ea7ce427f0219e7ebfa84ee4674df240d1a 100644 --- a/core/modules/locale/src/Tests/LocaleExportTest.php +++ b/core/modules/locale/src/Tests/LocaleExportTest.php @@ -43,7 +43,7 @@ protected function setUp() { public function testExportTranslation() { // First import some known translations. // This will also automatically add the 'fr' language. - $name = tempnam('temporary://', "po_") . '.po'; + $name = \Drupal::service('file_system')->tempnam('temporary://', "po_") . '.po'; file_put_contents($name, $this->getPoFile()); $this->drupalPostForm('admin/config/regional/translate/import', array( 'langcode' => 'fr', @@ -62,7 +62,7 @@ public function testExportTranslation() { $this->assertRaw('msgstr "lundi"', 'French translations present in exported file.'); // Import some more French translations which will be marked as customized. - $name = tempnam('temporary://', "po2_") . '.po'; + $name = \Drupal::service('file_system')->tempnam('temporary://', "po2_") . '.po'; file_put_contents($name, $this->getCustomPoFile()); $this->drupalPostForm('admin/config/regional/translate/import', array( 'langcode' => 'fr', diff --git a/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php b/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php index 0b69da257f822311b0fac04fd9284436822d04a4..7fb93d9309f6c3726f8a0213cabb1c691e0168c5 100644 --- a/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php +++ b/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php @@ -369,7 +369,7 @@ public function testCreatedLanguageTranslation() { * (optional) Additional options to pass to the translation import form. */ public function importPoFile($contents, array $options = array()) { - $name = tempnam('temporary://', "po_") . '.po'; + $name = \Drupal::service('file_system')->tempnam('temporary://', "po_") . '.po'; file_put_contents($name, $contents); $options['files[file]'] = $name; $this->drupalPostForm('admin/config/regional/translate/import', $options, t('Import')); diff --git a/core/modules/locale/src/Tests/LocalePluralFormatTest.php b/core/modules/locale/src/Tests/LocalePluralFormatTest.php index 00fe8d58a4533d880d8efe8f58ae556cd0e73bb3..c0e9041f051507a2dd64ab65fdeb978a2748e821 100644 --- a/core/modules/locale/src/Tests/LocalePluralFormatTest.php +++ b/core/modules/locale/src/Tests/LocalePluralFormatTest.php @@ -351,7 +351,7 @@ public function testPluralEditExport() { * Additional options to pass to the translation import form. */ public function importPoFile($contents, array $options = array()) { - $name = tempnam('temporary://', "po_") . '.po'; + $name = \Drupal::service('file_system')->tempnam('temporary://', "po_") . '.po'; file_put_contents($name, $contents); $options['files[file]'] = $name; $this->drupalPostForm('admin/config/regional/translate/import', $options, t('Import')); diff --git a/core/modules/system/src/Tests/Theme/TwigTransTest.php b/core/modules/system/src/Tests/Theme/TwigTransTest.php index b8718e7fa8701963accd221a2ad6718a6b0ba181..ef6fe05074f0dae23ca62f71e70649191ccae2cd 100644 --- a/core/modules/system/src/Tests/Theme/TwigTransTest.php +++ b/core/modules/system/src/Tests/Theme/TwigTransTest.php @@ -209,7 +209,7 @@ protected function installLanguages() { $this->assertRaw('"edit-languages-' . $langcode . '-weight"', 'Language code found.'); // Import the custom .po contents for the language. - $filename = tempnam('temporary://', "po_") . '.po'; + $filename = \Drupal::service('file_system')->tempnam('temporary://', "po_") . '.po'; file_put_contents($filename, $contents); $options = array( 'files[file]' => $filename,