You are here

public function SlickViews::render in Slick Views 7.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/style/SlickViews.php \Drupal\slick_views\Plugin\views\style\SlickViews::render()
  2. 8 src/Plugin/views/style/SlickViews.php \Drupal\slick_views\Plugin\views\style\SlickViews::render()

Overrides StylePluginBase::render().

Overrides views_plugin_style::render

File

src/Plugin/views/style/SlickViews.php, line 23

Class

SlickViews
Slick style plugin.

Namespace

Drupal\slick_views\Plugin\views\style

Code

public function render() {
  $settings = $this
    ->buildSettings();
  $elements = [];
  foreach ($this
    ->render_grouping($this->view->result, $settings['grouping']) as $rows) {
    $build = $this
      ->buildElements($settings, $rows);

    // Extracts Blazy formatter settings if available.
    if (empty($settings['vanilla']) && isset($build['items'][0])) {
      $this
        ->blazyManager()
        ->isBlazy($settings, $build['items'][0]);
    }

    // Supports Blazy multi-breakpoint images if using Blazy formatter.
    $settings['first_image'] = isset($rows[0]) ? $this
      ->getFirstImage($rows[0]) : [];
    $build['settings'] = $settings;
    $elements = $this
      ->manager()
      ->build($build);
    unset($build);
  }

  // Attach library if there is no results and ajax is active,
  // otherwise library will not be attached on ajax callback.
  // Note the empty space, a trick to solve: Undefined variable: empty...
  // No markup is output, yet the library is still attached on the page.
  // When this is reached, the $elements is an empty array.
  if (empty($this->view->result) && $this->view->use_ajax) {
    $elements['#markup'] = ' ';
    $elements['#attached'] = $this
      ->manager()
      ->attach($settings);
  }
  return $elements;
}