diff --git a/core/core.services.yml b/core/core.services.yml index 3e2feb6..a5a41ba 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -879,7 +879,7 @@ services: parent: default_plugin_manager stream_wrapper_manager: class: Drupal\Core\StreamWrapper\StreamWrapperManager - arguments: ['@module_handler'] + arguments: ['@event_dispatcher', '@config.factory'] calls: - [setContainer, ['@service_container']] stream_wrapper.public: diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index c3f15db..5ba6971 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -342,7 +342,6 @@ function install_begin_request($class_loader, &$install_state) { // Register the stream wrapper manager. $container ->register('stream_wrapper_manager', 'Drupal\Core\StreamWrapper\StreamWrapperManager') - ->addArgument(new Reference('module_handler')) ->addMethodCall('setContainer', array(new Reference('service_container'))); \Drupal::setContainer($container); diff --git a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperAlterEvent.php b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperAlterEvent.php new file mode 100644 index 0000000..bf23183 --- /dev/null +++ b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperAlterEvent.php @@ -0,0 +1,95 @@ +streamWrappers = $stream_wrappers; + } + + /** + * Sets the stream wrapper for a given name. + * + * @param string $name + * The name for the stream wrapper. + * @param array $info + * An associative array with the keys class, type and (optionally) + * service_id, and string values. + * + * @return $this + */ + public function setStreamWrapper($name, array $info) { + $this->streamWrappers[$name] = $info; + return $this; + } + + /** + * Returns the stream wrapper info for a given name. + * + * @param string $name + * The name of the stream wrapper. + * + * @return array + * An associative array with the keys class, type and (optionally) + * service_id, and string values. + */ + public function getStreamWrapper($name) { + if (isset($this->streamWrappers[$name])) { + return $this->streamWrappers[$name]; + } + } + + /** + * Returns whether there is a stream wrapper for the given name. + * + * @param string $name + * The name of the stream wrapper. + * + * @return bool + * TRUE if the stream wrappers exits. + */ + public function hasStreamWrapper($name) { + return isset($this->streamWrappers[$name]); + } + + /** + * Returns the stream wrapper information. + * + * @return array + * An associative array where keys are scheme names and values are + * themselves associative arrays with the keys class, type and (optionally) + * service_id, and string values. + */ + public function getStreamWrappers() { + return $this->streamWrappers; + } + +} diff --git a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperEvents.php b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperEvents.php new file mode 100644 index 0000000..e03cac9 --- /dev/null +++ b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperEvents.php @@ -0,0 +1,24 @@ +moduleHandler = $module_handler; + public function __construct(EventDispatcherInterface $dispatcher = NULL, ConfigFactoryInterface $config_factory = NULL) { + $this->dispatcher = $dispatcher; + $this->configFactory = $config_factory; } /** @@ -279,7 +292,16 @@ public function addStreamWrapper($service_id, $class, $scheme) { * Internal use only. */ public function register() { - $this->moduleHandler->alter('stream_wrappers', $this->info); + // Only expose the private file stream wrapper if a file path has been set. + // @todo Convert this to settings to avoid loading this from the + // configuration system early in the request. + if (!$this->configFactory || !$this->configFactory->get('system.file')->get('path.private')) { + unset($this->info['private']); + } + if ($this->dispatcher) { + $event = new StreamWrapperAlterEvent($this->info); + $this->info = $this->dispatcher->dispatch(StreamWrapperEvents::ALTER, $event)->getStreamWrappers(); + } foreach ($this->info as $scheme => $info) { $this->registerWrapper($scheme, $info['class'], $info['type']); diff --git a/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php index f26c5d4..c055553 100644 --- a/core/modules/simpletest/src/KernelTestBase.php +++ b/core/modules/simpletest/src/KernelTestBase.php @@ -314,8 +314,7 @@ public function containerBuild(ContainerBuilder $container) { // Register the stream wrapper manager. $container ->register('stream_wrapper_manager', 'Drupal\Core\StreamWrapper\StreamWrapperManager') - ->addArgument(new Reference('module_handler')) - ->addMethodCall('setContainer', array(new Reference('service_container'))); + ->setArguments([new Reference('service_container'), new Reference('config.factory')]); $request = Request::create('/'); $container->get('request_stack')->push($request); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 7b75cc9..8f2a8ab 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -307,16 +307,6 @@ function system_theme_suggestions_field(array $variables) { } /** - * Implements hook_stream_wrappers_alter(). - */ -function system_stream_wrappers_alter(&$wrappers) { - // Only register the private file stream wrapper if a file path has been set. - if (!\Drupal::config('system.file')->get('path.private')) { - unset($wrappers['private']); - } -} - -/** * Menu item access callback - only installed themes can be accessed. */ function _system_themes_access($theme) {