You are here

public static function InsertUtility::buildDerivativeUrl in Insert 8.2

Parameters

\Drupal\file\FileInterface $file:

string $styleName:

bool (optional) $absolute:

Return value

null|string

2 calls to InsertUtility::buildDerivativeUrl()
insert_colorbox_insert_variables in modules/insert_colorbox/insert_colorbox.module
Implements hook_insert_variables().
insert_insert_variables in ./insert.module
Implements hook_insert_variables().

File

src/Utility/InsertUtility.php, line 122

Class

InsertUtility

Namespace

Drupal\insert\Utility

Code

public static function buildDerivativeUrl(FileInterface $file, $styleName, $absolute = FALSE) {

  /** @var \Drupal\image\Entity\ImageStyle $style */
  $style = ImageStyle::load($styleName);
  if ($style !== NULL) {
    $url = $style
      ->buildUrl($file
      ->getFileUri());
    if (!$absolute) {
      $parsedUrl = parse_url($url);
      $url = $parsedUrl['path'];
      if (!empty($parsedUrl['query'])) {
        $url .= '?' . $parsedUrl['query'];
      }
    }
    return $url;
  }
  return NULL;
}