You are here

public static function Blazy::urlAndDimensions in Blazy 8.2

Same name and namespace in other branches
  1. 7 src/Blazy.php \Drupal\blazy\Blazy::urlAndDimensions()

Builds URLs, cache tags, and dimensions for an individual image.

Respects a few scenarios: 1. Blazy Filter or unmanaged file with/ without valid URI. 2. Hand-coded image_url with/ without valid URI. 3. Respects first_uri without image_url such as colorbox/zoom-like. 4. File API via field formatters or Views fields/ styles with valid URI. If we have a valid URI, provides the correct image URL. Otherwise leave it as is, likely hotlinking to external/ sister sites. Hence URI validity is not crucial in regards to anything but #4. The image will fail silently at any rate given non-expected URI.

Parameters

array $settings: The given settings being modified.

object $item: The image item.

Overrides BlazyInterface::urlAndDimensions

2 calls to Blazy::urlAndDimensions()
Blazy::preprocessBlazy in src/Blazy.php
Prepares variables for blazy.html.twig templates.
BlazyManager::prepareBlazy in src/BlazyManager.php
Prepares the Blazy output as a structured array ready for ::renderer().

File

src/Blazy.php, line 103

Class

Blazy
Provides common blazy utility static methods.

Namespace

Drupal\blazy

Code

public static function urlAndDimensions(array &$settings, $item = NULL) {

  // BlazyFilter, or image style with crop, may already set these.
  BlazyUtil::imageDimensions($settings, $item);

  // Provides image url based on the given settings.
  BlazyUtil::imageUrl($settings);

  // The SVG placeholder should accept either original, or styled image.
  $is_media = in_array($settings['type'], [
    'audio',
    'video',
  ]);
  $settings['placeholder'] = empty($settings['placeholder']) ? BlazyUtil::generatePlaceholder($settings['width'], $settings['height']) : $settings['placeholder'];
  $settings['use_media'] = $settings['embed_url'] && $is_media;
  $settings['use_loading'] = empty($settings['is_preview']) ? $settings['use_loading'] : FALSE;
}