You are here

protected function BlazyFormatter::setImageDimensions in Blazy 7

Same name and namespace in other branches
  1. 8.2 src/BlazyFormatter.php \Drupal\blazy\BlazyFormatter::setImageDimensions()

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

Parameters

array $settings: The settings being modified.

1 call to BlazyFormatter::setImageDimensions()
BlazyFormatter::preBuildElements in src/BlazyFormatter.php

File

src/BlazyFormatter.php, line 161

Class

BlazyFormatter
Implements BlazyFormatterInterface.

Namespace

Drupal\blazy

Code

protected function setImageDimensions(array &$settings = []) {
  if (!isset($this->isImageDimensionSet[md5($settings['id'])])) {

    // If image style contains crop, sets dimension once, and let all inherit.
    if (!empty($settings['image_style']) && $this
      ->isCrop($settings['image_style'])) {
      $settings = array_merge($settings, Blazy::transformDimensions($settings['image_style'], $this->firstItem));

      // Informs individual images that dimensions are already set once.
      // @todo re-enable $settings['_dimensions'] = TRUE;
      // @fixme Unlike D8, this makes the first item has different dimensions.
    }

    // Also sets breakpoint dimensions once, if cropped.
    // @todo TBD; for keeping or removal at blazy:7.x-2.0.
    if (!empty($settings['breakpoints'])) {
      $this
        ->buildDataBlazy($settings, $this->firstItem);
    }
    $this->isImageDimensionSet[md5($settings['id'])] = TRUE;
  }
}