Skip to content
Snippets Groups Projects

Resolve #3354894 "Cloudinary stream wrapper"

2 files
+ 16
5
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -7,6 +7,7 @@ use Cloudinary\Asset\AssetType;
use Cloudinary\Asset\DeliveryType;
use Cloudinary\Configuration\Configuration;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\Url;
/**
* Implement DrupalStreamWrapperInterface with cloudinary[.folder]://.
@@ -309,12 +310,13 @@ class CloudinaryStreamWrapper implements StreamWrapperInterface {
[, $transformation, $target] = $matches;
}
$public_id = $target;
// Extract format.
$parts = explode('.', $target);
if (count($parts) > 1) {
$format = array_pop($parts);
}
$public_id = implode('.', $parts);
return [
'style_name' => $style_name ?? NULL,
@@ -364,9 +366,12 @@ class CloudinaryStreamWrapper implements StreamWrapperInterface {
];
$resource = cloudinary_stream_wrapper_load_file($info['public_id'], $options);
// Try to load resource by target (includes file extension).
if (!$resource) {
$resource = cloudinary_stream_wrapper_load_file($info['target'], $options);
// If the asset wasn't saved yet and the resource doesn't exist on
// Cloudinary anymore it is not possible to build a URL.
if (!isset($resource['secure_url'])) {
// Return the URL to the root of the site because the method requires
// a valid URL to be returned.
return Url::fromUserInput('/', ['absolute' => TRUE])->toString();
}
return $resource['secure_url'];
Loading