You are here

public function BlazyFormatter::preBuildElements in Blazy 7

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

File

src/BlazyFormatter.php, line 100

Class

BlazyFormatter
Implements BlazyFormatterInterface.

Namespace

Drupal\blazy

Code

public function preBuildElements(array &$build, $items, $entity, array $entities = []) {
  $this
    ->buildSettings($build, $items, $entity);
  $settings =& $build['settings'];

  // Pass first item to optimize sizes this time.
  if (isset($items[0]) && ($item = $items[0])) {
    $this
      ->extractFirstItem($settings, $item, reset($entities));
  }

  // Sets dimensions once, if cropped, to reduce costs with ton of images.
  // This is less expensive than re-defining dimensions per image.
  // @todo remove first_uri for _uri for consistency.
  if ((!empty($settings['_uri']) || !empty($settings['first_uri'])) && !$settings['resimage']) {
    $this
      ->setImageDimensions($settings);
  }

  // Add the entity to formatter cache tags.
  // @todo $settings['cache_tags'][] = $settings['entity_type_id'] . ':' . $settings['entity_id'];
  // Sniffs for Views to allow block__no_wrapper, views_no_wrapper, etc.
  if (function_exists('views_get_current_view') && ($view = views_get_current_view())) {
    $settings['view_name'] = $view->name;
    $settings['current_view_mode'] = $view->current_display;
    $settings['view_plugin_id'] = $view->style_plugin->plugin_name;
  }

  // Allows altering the settings.
  drupal_alter('blazy_settings', $build, $items);
}