Skip to content
Snippets Groups Projects

Resolve #3376892 "Move streamwrappers from"

1 unresolved thread
Files
13
@@ -5,6 +5,7 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\File\Exception\InvalidStreamWrapperException;
use Drupal\Core\StreamWrapper\StreamWrapperGetUrlInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\Core\Url;
@@ -98,7 +99,14 @@ protected function doGenerateString(string $uri, bool $relative): string {
// implement getExternalUrl() for the HTTP and data schemes.
return $relative ? $this->transformRelative($uri) : $uri;
}
elseif ($scheme === 'vfs') {
return $uri;
}
elseif ($wrapper = $this->streamWrapperManager->getViaUri($uri)) {
if ($wrapper instanceof StreamWrapperGetUrlInterface) {
return $wrapper->getUrl()->setAbsolute(!$relative)->toString();
}
@trigger_error('Implementing \Drupal\Core\StreamWrapper\StreamWrapperInterface without implementing \Drupal\Core\StreamWrapper\StreamWrapperGetUrlInterface is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Implement \Drupal\Core\StreamWrapper\StreamWrapperGetUrlInterface for ' . get_class($wrapper) . '. See https://www.drupal.org/project/drupal/issues/3376892', E_USER_DEPRECATED);
// Attempt to return an external URL using the appropriate wrapper.
$externalUrl = $wrapper->getExternalUrl();
return $relative ? $this->transformRelative($externalUrl) : $externalUrl;
@@ -186,6 +194,11 @@ public function generate(string $uri): Url {
return Url::fromUri(urldecode($options['path']), $options);
}
elseif ($wrapper = $this->streamWrapperManager->getViaUri($uri)) {
if ($wrapper instanceof StreamWrapperGetUrlInterface) {
// Relative URL is being expected for local URLs (matching domain).
return $wrapper->getUrl()->setAbsolute(FALSE);
}
@trigger_error('Implementing \Drupal\Core\StreamWrapper\StreamWrapperInterface without implementing \Drupal\Core\StreamWrapper\StreamWrapperGetUrlInterface is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Implement \Drupal\Core\StreamWrapper\StreamWrapperGetUrlInterface for ' . get_class($wrapper) . '. See https://www.drupal.org/project/drupal/issues/3376892', E_USER_DEPRECATED);
$external_url = $wrapper->getExternalUrl();
$options = UrlHelper::parse($external_url);
Loading