diff --git a/core/modules/system/src/Form/ThemeSettingsForm.php b/core/modules/system/src/Form/ThemeSettingsForm.php index 6d9a143..38fa098 100644 --- a/core/modules/system/src/Form/ThemeSettingsForm.php +++ b/core/modules/system/src/Form/ThemeSettingsForm.php @@ -17,6 +17,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\ConfigFormBase; +use Drupal\Core\File\FileSystemInterface; /** * Displays theme configuration for entire site and individual themes. @@ -38,6 +39,12 @@ class ThemeSettingsForm extends ConfigFormBase { protected $themeHandler; /** + * File System instance. + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + + /** * The MIME type guesser. * * @var \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface @@ -62,13 +69,16 @@ class ThemeSettingsForm extends ConfigFormBase { * The theme handler. * @param \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface $mime_type_guesser * The MIME type guesser instance to use. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * The FileSytem instance to use. */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, MimeTypeGuesserInterface $mime_type_guesser) { + public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, MimeTypeGuesserInterface $mime_type_guesser, FileSystemInterface $file_system) { parent::__construct($config_factory); $this->moduleHandler = $module_handler; $this->themeHandler = $theme_handler; $this->mimeTypeGuesser = $mime_type_guesser; + $this->fileSystem = $file_system; } /** @@ -79,7 +89,8 @@ public static function create(ContainerInterface $container) { $container->get('config.factory'), $container->get('module_handler'), $container->get('theme_handler'), - $container->get('file.mime_type.guesser') + $container->get('file.mime_type.guesser'), + $container->get('file_system') ); } @@ -466,7 +477,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { */ protected function validatePath($path) { // Absolute local file paths are invalid. - if (\Drupal::service('file_system')->realpath($path) == $path) { + if ($this->fileSystem->realpath($path) == $path) { return FALSE; } // A path relative to the Drupal root or a fully qualified URI is valid. diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index d68fe03..08b2f5b 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\Color; use Drupal\Component\Utility\Unicode; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\ImageToolkit\ImageToolkitBase; use Drupal\Core\ImageToolkit\ImageToolkitOperationManagerInterface; @@ -65,6 +66,13 @@ class GDToolkit extends ImageToolkitBase { protected $streamWrapperManager; /** + * File System instance. + * + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + + /** * Constructs a GDToolkit object. * * @param array $configuration @@ -81,10 +89,13 @@ class GDToolkit extends ImageToolkitBase { * The config factory. * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager * The StreamWrapper manager. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * The FileSytem instance to use. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger, ConfigFactoryInterface $config_factory, StreamWrapperManagerInterface $stream_wrapper_manager) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger, ConfigFactoryInterface $config_factory, StreamWrapperManagerInterface $stream_wrapper_manager, FileSystemInterface $file_system) { parent::__construct($configuration, $plugin_id, $plugin_definition, $operation_manager, $logger, $config_factory); $this->streamWrapperManager = $stream_wrapper_manager; + $this->fileSystem = $file_system; } /** @@ -109,7 +120,8 @@ public static function create(ContainerInterface $container, array $configuratio $container->get('image.toolkit.operation.manager'), $container->get('logger.channel.image'), $container->get('config.factory'), - $container->get('stream_wrapper_manager') + $container->get('stream_wrapper_manager'), + $container->get('file_system') ); } @@ -229,7 +241,7 @@ public function save($destination) { $destination = drupal_tempnam('temporary://', 'gd_'); } // Convert stream wrapper URI to normal path. - $destination = \Drupal::service('file_system')->realpath($destination); + $destination = $this->fileSystem->realpath($destination); } $function = 'image' . image_type_to_extension($this->getType(), FALSE); diff --git a/core/modules/system/src/Tests/File/DirectoryTest.php b/core/modules/system/src/Tests/File/DirectoryTest.php index 4c15a8e..c5913df 100644 --- a/core/modules/system/src/Tests/File/DirectoryTest.php +++ b/core/modules/system/src/Tests/File/DirectoryTest.php @@ -49,7 +49,7 @@ function testFileCheckLocalDirectoryHandling() { $this->assertDirectoryPermissions($directory, $old_mode); // Check creating a directory using an absolute path. - $absolute_path = drupal_realpath($directory) . DIRECTORY_SEPARATOR . $this->randomMachineName() . DIRECTORY_SEPARATOR . $this->randomMachineName(); + $absolute_path = $this->container->get('file_system')->realpath($directory) . DIRECTORY_SEPARATOR . $this->randomMachineName() . DIRECTORY_SEPARATOR . $this->randomMachineName(); $this->assertTrue(drupal_mkdir($absolute_path, 0775, TRUE), 'No error reported when creating new absolute directories.', 'File'); $this->assertDirectoryPermissions($absolute_path, 0775); } diff --git a/core/modules/update/src/Form/UpdateReady.php b/core/modules/update/src/Form/UpdateReady.php index 0beafd1..fa31149 100644 --- a/core/modules/update/src/Form/UpdateReady.php +++ b/core/modules/update/src/Form/UpdateReady.php @@ -8,6 +8,7 @@ namespace Drupal\update\Form; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\FileTransfer\Local; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -50,6 +51,13 @@ class UpdateReady extends FormBase { protected $sitePath; /** + * File System instance. + * + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + + /** * Constructs a new UpdateReady object. * * @param string $root @@ -60,12 +68,15 @@ class UpdateReady extends FormBase { * The state key value store. * @param string $site_path * The site path. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * The FileSytem instance to use. */ - public function __construct($root, ModuleHandlerInterface $module_handler, StateInterface $state, $site_path) { + public function __construct($root, ModuleHandlerInterface $module_handler, StateInterface $state, $site_path, FileSystemInterface $file_system) { $this->root = $root; $this->moduleHandler = $module_handler; $this->state = $state; $this->sitePath = $site_path; + $this->fileSystem = $file_system; } /** @@ -83,7 +94,8 @@ public static function create(ContainerInterface $container) { $container->get('update.root'), $container->get('module_handler'), $container->get('state'), - $container->get('site.path') + $container->get('site.path'), + $container->get('file_system') ); } @@ -141,7 +153,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { foreach ($projects as $project => $url) { $project_location = $directory . '/' . $project; $updater = Updater::factory($project_location, $this->root); - $project_real_location = \Drupal::service('file_system')->realpath($project_location); + $project_real_location = $this->fileSystem->realpath($project_location); $updates[] = array( 'project' => $project, 'updater_name' => get_class($updater),