Commit 31a5cba3 authored by larowlan's avatar larowlan

Issue #3049021 by kim.pepper, Berdir: Deprecate file_default_scheme() and just use config

parent e3aa75b9
......@@ -146,8 +146,14 @@ function file_uri_target($uri) {
*
* @return string
* 'public', 'private' or any other file scheme defined as the default.
*
* @deprecated in drupal:8.8.0 and will be removed from drupal:9.0.0. Use
* \Drupal::config('system.file')->get('default_scheme') instead.
*
* @see https://www.drupal.org/node/3049030
*/
function file_default_scheme() {
@trigger_error('file_default_scheme() is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Use \Drupal::config(\'system.file\')->get(\'default_scheme\') instead. See https://www.drupal.org/project/paragraphs/issues/3049030', E_USER_DEPRECATED);
return \Drupal::config('system.file')->get('default_scheme');
}
......@@ -579,7 +585,7 @@ function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_E
* Constructs a URI to Drupal's default files location given a relative path.
*/
function file_build_uri($path) {
$uri = file_default_scheme() . '://' . $path;
$uri = \Drupal::config('system.file')->get('default_scheme') . '://' . $path;
return file_stream_wrapper_uri_normalize($uri);
}
......
......@@ -226,7 +226,7 @@ function hook_modules_installed($modules) {
*/
function hook_install() {
// Create the styles directory and ensure it's writable.
$directory = file_default_scheme() . '://styles';
$directory = \Drupal::config('system.file')->get('default_scheme') . '://styles';
\Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
}
......@@ -283,7 +283,7 @@ function hook_modules_uninstalled($modules) {
*/
function hook_uninstall() {
// Remove the styles directory and generated images.
\Drupal::service('file_system')->deleteRecursive(file_default_scheme() . '://styles');
\Drupal::service('file_system')->deleteRecursive(\Drupal::config('system.file')->get('default_scheme') . '://styles');
}
/**
......
......@@ -30,7 +30,7 @@ function editor_image_upload_settings_form(Editor $editor) {
$image_upload = $editor->getImageUploadSettings();
$image_upload += [
'status' => FALSE,
'scheme' => file_default_scheme(),
'scheme' => \Drupal::config('system.file')->get('default_scheme'),
'directory' => 'inline-images',
'max_size' => '',
'max_dimensions' => ['width' => '', 'height' => ''],
......
......@@ -115,7 +115,7 @@ public function testLoading() {
'editor' => 'unicorn',
'image_upload' => [
'status' => FALSE,
'scheme' => file_default_scheme(),
'scheme' => 'public',
'directory' => 'inline-images',
'max_size' => '',
'max_dimensions' => ['width' => '', 'height' => ''],
......@@ -231,7 +231,7 @@ public function testSupportedElementTypes() {
'editor' => 'unicorn',
'image_upload' => [
'status' => FALSE,
'scheme' => file_default_scheme(),
'scheme' => 'public',
'directory' => 'inline-images',
'max_size' => '',
'max_dimensions' => ['width' => '', 'height' => ''],
......
......@@ -64,7 +64,7 @@ protected function createEntity() {
$camelids
->setImageUploadSettings([
'status' => FALSE,
'scheme' => file_default_scheme(),
'scheme' => 'public',
'directory' => 'inline-images',
'max_size' => '',
'max_dimensions' => [
......
......@@ -559,7 +559,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
$user = \Drupal::currentUser();
if (empty($destination)) {
$destination = file_default_scheme() . '://';
$destination = \Drupal::config('system.file')->get('default_scheme') . '://';
}
if (!file_valid_uri($destination)) {
\Drupal::logger('file')->notice('The data could not be saved because the destination %destination is invalid. This may be caused by improper use of file_save_data() or a missing stream wrapper.', ['%destination' => $destination]);
......
......@@ -38,7 +38,7 @@ public static function defaultStorageSettings() {
'target_type' => 'file',
'display_field' => FALSE,
'display_default' => FALSE,
'uri_scheme' => file_default_scheme(),
'uri_scheme' => \Drupal::config('system.file')->get('default_scheme'),
] + parent::defaultStorageSettings();
}
......
......@@ -184,7 +184,7 @@ public function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) {
$filepath = 'Файл для тестирования ' . $this->randomMachineName();
}
if (!isset($scheme)) {
$scheme = file_default_scheme();
$scheme = 'public';
}
$filepath = $scheme . '://' . $filepath;
......
......@@ -197,7 +197,7 @@ public function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) {
$filepath = 'Файл для тестирования ' . $this->randomMachineName();
}
if (!isset($scheme)) {
$scheme = file_default_scheme();
$scheme = 'public';
}
$filepath = $scheme . '://' . $filepath;
......
......@@ -20,7 +20,7 @@ public function testWithoutFilename() {
$result = file_save_data($contents);
$this->assertTrue($result, 'Unnamed file saved correctly.');
$this->assertEqual(file_default_scheme(), file_uri_scheme($result->getFileUri()), "File was placed in Drupal's files directory.");
$this->assertEqual(\Drupal::config('system.file')->get('default_scheme'), file_uri_scheme($result->getFileUri()), "File was placed in Drupal's files directory.");
$this->assertEqual($result->getFilename(), \Drupal::service('file_system')->basename($result->getFileUri()), "Filename was set to the file's basename.");
$this->assertEqual($contents, file_get_contents($result->getFileUri()), 'Contents of the file are correct.');
$this->assertEqual($result->getMimeType(), 'application/octet-stream', 'A MIME type was set.');
......
......@@ -13,7 +13,7 @@
*/
function image_install() {
// Create the styles directory and ensure it's writable.
$directory = file_default_scheme() . '://styles';
$directory = \Drupal::config('system.file')->get('default_scheme') . '://styles';
\Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
}
......@@ -25,7 +25,7 @@ function image_uninstall() {
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
try {
$file_system->deleteRecursive(file_default_scheme() . '://styles');
$file_system->deleteRecursive(\Drupal::config('system.file')->get('default_scheme') . '://styles');
}
catch (FileException $e) {
// Ignore failed deletes.
......
......@@ -539,17 +539,15 @@ protected function fileUriTarget($uri) {
}
/**
* Provides a wrapper for file_default_scheme() to allow unit testing.
* Provides a wrapper to allow unit testing.
*
* Gets the default file stream implementation.
*
* @todo: Convert file_default_scheme() into a proper injectable service.
*
* @return string
* 'public', 'private' or any other file scheme defined as the default.
*/
protected function fileDefaultScheme() {
return file_default_scheme();
return \Drupal::config('system.file')->get('default_scheme');
}
/**
......
......@@ -277,7 +277,7 @@ public function testStyle() {
$this->drupalPostForm($style_path . '/delete', [], t('Delete'));
// Confirm the style directory has been removed.
$directory = file_default_scheme() . '://styles/' . $style_name;
$directory = 'public://styles/' . $style_name;
$this->assertFalse(is_dir($directory), format_string('Image style %style directory removed on style deletion.', ['%style' => $style->label()]));
$this->assertFalse(ImageStyle::load($style_name), format_string('Image style %style successfully deleted.', ['%style' => $style->label()]));
......
......@@ -73,7 +73,7 @@ protected function createEntity() {
$camelids
->setImageUploadSettings([
'status' => FALSE,
'scheme' => file_default_scheme(),
'scheme' => 'public',
'directory' => 'inline-images',
'max_size' => '',
'max_dimensions' => [
......@@ -223,7 +223,7 @@ protected function createAnotherEntity($key) {
$entity->setImageUploadSettings([
'status' => FALSE,
'scheme' => file_default_scheme(),
'scheme' => 'public',
'directory' => 'inline-images',
'max_size' => '',
'max_dimensions' => [
......
......@@ -461,9 +461,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// If the user uploaded a new logo or favicon, save it to a permanent location
// and use it in place of the default theme-provided file.
$default_scheme = $this->config('system.file')->get('default_scheme');
try {
if (!empty($values['logo_upload'])) {
$filename = $this->fileSystem->copy($values['logo_upload']->getFileUri(), file_default_scheme() . '://');
$filename = $this->fileSystem->copy($values['logo_upload']->getFileUri(), $default_scheme . '://');
$values['default_logo'] = 0;
$values['logo_path'] = $filename;
}
......@@ -473,7 +474,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}
try {
if (!empty($values['favicon_upload'])) {
$filename = $this->fileSystem->copy($values['favicon_upload']->getFileUri(), file_default_scheme() . '://');
$filename = $this->fileSystem->copy($values['favicon_upload']->getFileUri(), $default_scheme . '://');
$values['default_favicon'] = 0;
$values['favicon_path'] = $filename;
$values['toggle_favicon'] = 1;
......
......@@ -711,7 +711,7 @@ function system_requirements($phase) {
else {
// This function can be called before the config_cache table has been
// created.
if ($phase == 'install' || file_default_scheme() == 'public') {
if ($phase == 'install' || \Drupal::config('system.file')->get('default_scheme') == 'public') {
$requirements['file system']['value'] = t('Writable (<em>public</em> download method)');
}
else {
......
......@@ -21,7 +21,7 @@ class FolderTest extends BrowserTestBase {
public static $modules = ['image'];
public function testFolderSetup() {
$directory = file_default_scheme() . '://styles';
$directory = 'public://styles';
$this->assertTrue(\Drupal::service('file_system')->prepareDirectory($directory, FALSE), 'Directory created.');
}
......
......@@ -59,7 +59,8 @@ public function testFileCheckLocalDirectoryHandling() {
*/
public function testFileCheckDirectoryHandling() {
// A directory to operate on.
$directory = file_default_scheme() . '://' . $this->randomMachineName() . '/' . $this->randomMachineName();
$default_scheme = 'public';
$directory = $default_scheme . '://' . $this->randomMachineName() . '/' . $this->randomMachineName();
$this->assertFalse(is_dir($directory), 'Directory does not exist prior to testing.');
// Non-existent directory.
......@@ -92,12 +93,12 @@ public function testFileCheckDirectoryHandling() {
$this->assertDirectoryPermissions($directory, 0777, 'file_chmod_directory setting is respected.');
// Remove .htaccess file to then test that it gets re-created.
@$file_system->unlink(file_default_scheme() . '://.htaccess');
$this->assertFalse(is_file(file_default_scheme() . '://.htaccess'), 'Successfully removed the .htaccess file in the files directory.', 'File');
@$file_system->unlink($default_scheme . '://.htaccess');
$this->assertFalse(is_file($default_scheme . '://.htaccess'), 'Successfully removed the .htaccess file in the files directory.', 'File');
file_ensure_htaccess();
$this->assertTrue(is_file(file_default_scheme() . '://.htaccess'), 'Successfully re-created the .htaccess file in the files directory.', 'File');
$this->assertTrue(is_file($default_scheme . '://.htaccess'), 'Successfully re-created the .htaccess file in the files directory.', 'File');
// Verify contents of .htaccess file.
$file = file_get_contents(file_default_scheme() . '://.htaccess');
$file = file_get_contents($default_scheme . '://.htaccess');
$this->assertEqual($file, FileStorage::htaccessLines(FALSE), 'The .htaccess file contains the proper content.', 'File');
}
......
......@@ -14,7 +14,7 @@ class FileDeleteRecursiveTest extends FileTestBase {
*/
public function testSingleFile() {
// Create a file for testing
$filepath = file_default_scheme() . '://' . $this->randomMachineName();
$filepath = 'public://' . $this->randomMachineName();
file_put_contents($filepath, '');
// Delete the file.
......
......@@ -28,7 +28,7 @@ public function testNormal() {
*/
public function testMissing() {
// Try to delete a non-existing file
$this->assertTrue(\Drupal::service('file_system')->delete(file_default_scheme() . '/' . $this->randomMachineName()), 'Returns true when deleting a non-existent file.');
$this->assertTrue(\Drupal::service('file_system')->delete('public://' . $this->randomMachineName()), 'Returns true when deleting a non-existent file.');
}
/**
......
......@@ -162,4 +162,11 @@ public function testUnlink() {
$this->assertFileNotExists($uri);
}
/**
* @expectedDeprecation file_default_scheme() is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Use \Drupal::config('system.file')->get('default_scheme') instead. See https://www.drupal.org/project/paragraphs/issues/3049030
*/
public function testDeprecatedDefaultScheme() {
$this->assertNotNull(file_default_scheme());
}
}
......@@ -162,7 +162,7 @@ public function assertDirectoryPermissions($directory, $expected_mode, $message
public function createDirectory($path = NULL) {
// A directory to operate on.
if (!isset($path)) {
$path = file_default_scheme() . '://' . $this->randomMachineName();
$path = 'public://' . $this->randomMachineName();
}
$this->assertTrue(\Drupal::service('file_system')->mkdir($path) && is_dir($path), 'Directory was created successfully.');
return $path;
......@@ -190,7 +190,7 @@ public function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) {
$filepath = 'Файл для тестирования ' . $this->randomMachineName();
}
if (!isset($scheme)) {
$scheme = file_default_scheme();
$scheme = 'public';
}
$filepath = $scheme . '://' . $filepath;
......
......@@ -215,7 +215,6 @@ public function testRenderWithTheme() {
* @covers ::bootKernel
*/
public function testFileDefaultScheme() {
$this->assertEquals('public', file_default_scheme());
$this->assertEquals('public', \Drupal::config('system.file')->get('default_scheme'));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment