You are here

public function BlazyManager::setDimensionsOnce in Blazy 8

Sets dimensions once to reduce method calls, if image style contains crop.

The implementor should only call this if not using Responsive image style.

Parameters

array $settings: The settings being modified.

1 call to BlazyManager::setDimensionsOnce()
BlazyFormatterManager::buildSettings in src/BlazyFormatterManager.php
Returns the field formatter settings inherited by child elements.

File

src/BlazyManager.php, line 53

Class

BlazyManager
Implements a public facing blazy manager.

Namespace

Drupal\blazy

Code

public function setDimensionsOnce(array &$settings = []) {
  $item = isset($settings['item']) ? $settings['item'] : NULL;
  $dimensions['width'] = $settings['original_width'] = isset($item->width) ? $item->width : NULL;
  $dimensions['height'] = $settings['original_height'] = isset($item->height) ? $item->height : NULL;

  // If image style contains crop, sets dimension once, and let all inherit.
  if (!empty($settings['image_style']) && ($style = $this
    ->entityLoad($settings['image_style']))) {
    if ($this
      ->isCrop($style)) {
      $style
        ->transformDimensions($dimensions, $settings['uri']);
      $settings['height'] = $dimensions['height'];
      $settings['width'] = $dimensions['width'];

      // Informs individual images that dimensions are already set once.
      $settings['_dimensions'] = TRUE;
    }
  }

  // Also sets breakpoint dimensions once, if cropped.
  if (!empty($settings['breakpoints'])) {
    $this
      ->buildDataBlazy($settings, $item);
  }

  // Remove these since this method is meant for top-level container.
  unset($settings['uri'], $settings['item']);
}