By berdir on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Issue links:
Description:
hook_stream_wrappers() has been removed in favor of tagged services. This change was made to avoid calling a hook in the early bootstrap process.
Drupal 7
function system_stream_wrappers() {
$wrappers = array(
'public' => array(
'name' => t('Public files'),
'class' => 'DrupalPublicStreamWrapper',
'description' => t('Public local files served by the webserver.'),
'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
),
// Only register the private file stream wrapper if a file path has been set.
if (variable_get('file_private_path', FALSE)) {
$wrappers['private'] = array(
'name' => t('Private files'),
'class' => 'DrupalPrivateStreamWrapper',
'description' => t('Private local files served by Drupal.'),
'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
);
}
return $wrappers;
}
Drupal 8
To define a stream wrapper that is always available, define it in yourmodule.services.yml like this:
stream_wrapper.public:
class: Drupal\Core\StreamWrapper\PublicStream
tags:
- { name: stream_wrapper, scheme: public }
If a stream wrapper should only be available dynamically, like private://, use a ServiceProvider:
class CoreServiceProvider implements ServiceProviderInterface {
public function register(ContainerBuilder $container) {
// Only register the private file stream wrapper if a file path has been set.
if (Settings::get('file_private_path')) {
$container->register('stream_wrapper.private', 'Drupal\Core\StreamWrapper\PrivateStream')
->addTag('stream_wrapper', ['scheme' => 'private']);
}
}
}
hook_stream_wrappers_alter() has been removed. Use ServiceProvider::alter() to change the defined service.
The label and description are now methods on the service, to change them, the class needs to be replaced.
The following functions have been moved to the stream wrapper manager:
Drupal 7
file_get_stream_wrappers($filter)
file_stream_wrapper_get_class($scheme)
file_stream_wrapper_get_instance_by_uri($uri)
file_stream_wrapper_get_instance_by_scheme($scheme)
Drupal 8
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');
$stream_wrapper_manager->getWrappers($filter)
$stream_wrapper_manager->getClass($scheme)
$stream_wrapper_manager->getViaUri($uri)
$stream_wrapper_manager->getViaScheme($scheme)
Impacts:
Module developers