You are here

public function ImageStyle::buildUri in Remote Stream Wrapper 8

Returns the URI of this image when using this style.

The path returned by this function may not exist. The default generation method only creates images when they are requested by a user's browser. Modules may implement this method to decide where to place derivatives.

Parameters

string $uri: The URI or path to the original image.

Return value

string The URI to the image derivative for this style.

Overrides ImageStyle::buildUri

File

src/Entity/ImageStyle.php, line 16

Class

ImageStyle
Overrides the ImageStyle entity class to support remote image derivatives.

Namespace

Drupal\remote_stream_wrapper\Entity

Code

public function buildUri($uri) {
  if ($this
    ->fileIsUriRemote($uri)) {

    // Reroute derivatives of remote images through the default file system.
    $scheme = StreamWrapperManager::getScheme($uri);
    $path = StreamWrapperManager::getTarget($uri);

    // @todo Use $this->fileDefaultScheme() instead of hard-coding to public.
    return 'public://styles/' . $this
      ->id() . '/' . $scheme . '/' . $this
      ->addExtension($path);
  }
  else {
    return parent::buildUri($uri);
  }
}