You are here

protected function Textimage::buildUri in Textimage 8.4

Same name and namespace in other branches
  1. 8.3 src/Textimage.php \Drupal\textimage\Textimage::buildUri()

Set URI to image file.

An appropriate directory structure is in place to support styled, unstyled and uncached (temporary) image files:

for images with a supporting image style (styled) - {style_wrapper}://textimage_store/cache/styles/{style}/{substr(file name, 1)}/{substr(file name, 2)}/{file name}.{extension}

for images generated via direct theme (unstyled) - {default_wrapper}://textimage_store/cache/api/{substr(file name, 1)}/{substr(file name, 2)}/{file name}.{extension}

for uncached, temporary - {default_wrapper}://textimage_store/temp/{file name}.{extension}

Return value

$this

1 call to Textimage::buildUri()
Textimage::process in src/Textimage.php
Process the Textimage, with the required raw text.

File

src/Textimage.php, line 858

Class

Textimage
Provides a Textimage.

Namespace

Drupal\textimage

Code

protected function buildUri() {

  // @codingStandardsIgnoreEnd
  // The file name will be the Textimage hash.
  if ($this->caching) {
    $base_name = $this->id . '.' . $this->extension;
    if ($this->style) {
      $scheme = $this->style
        ->getThirdPartySetting('textimage', 'uri_scheme', $this->configFactory
        ->get('system.file')
        ->get('default_scheme'));
      $this
        ->set('uri', $this->factory
        ->getStoreUri('/cache/styles/', $scheme) . $this->style
        ->id() . '/' . substr($base_name, 0, 1) . '/' . substr($base_name, 0, 2) . '/' . $base_name);
    }
    else {
      $this
        ->set('uri', $this->factory
        ->getStoreUri('/cache/api/') . substr($base_name, 0, 1) . '/' . substr($base_name, 0, 2) . '/' . $base_name);
    }
  }
  else {
    $base_name = hash('sha256', session_id() . microtime()) . '.' . $this->extension;
    $this
      ->set('uri', $this->factory
      ->getStoreUri('/temp/') . $base_name);
  }
  return $this;
}