You are here

public function BlazyViews::render in Blazy 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/style/BlazyViews.php \Drupal\blazy\Plugin\views\style\BlazyViews::render()
  2. 7 src/Plugin/views/style/BlazyViews.php \Drupal\blazy\Plugin\views\style\BlazyViews::render()

Overrides StylePluginBase::render().

Overrides StylePluginBase::render

File

src/Plugin/views/style/BlazyViews.php, line 103

Class

BlazyViews
Blazy style plugin.

Namespace

Drupal\blazy\Plugin\views\style

Code

public function render() {
  $settings = $this->options;
  $settings['count'] = count($this->view->result);
  $settings['current_view_mode'] = $this->view->current_display;
  $settings['item_id'] = 'content';
  $settings['namespace'] = 'blazy';
  $settings['view_name'] = $this->view->storage
    ->id();
  $elements = [];
  foreach ($this
    ->renderGrouping($this->view->result, $settings['grouping']) as $rows) {
    $items = [];
    foreach ($rows as $index => $row) {
      $this->view->row_index = $index;
      $items[$index] = $this->view->rowPlugin
        ->render($row);
    }

    // Supports Blazy formatter multi-breakpoint images if available.
    $item = isset($items[0]) ? $items[0] : NULL;
    $this->blazyManager
      ->isBlazy($settings, $item);
    $elements = BlazyGrid::build($items, $settings);
    $elements['#attached'] = $this->blazyManager
      ->attach($settings);
    unset($this->view->row_index, $items);
  }
  return $elements;
}