You are here

public function SlickViews::render in Slick Views 8

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. 7.3 src/Plugin/views/style/SlickViews.php \Drupal\slick_views\Plugin\views\style\SlickViews::render()

Overrides StylePluginBase::render().

File

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

Class

SlickViews
Slick style plugin.

Namespace

Drupal\slick_views\Plugin\views\style

Code

public function render() {
  $view = $this->view;
  $count = count($view->result);
  $settings = $this->options;
  $view_name = $view->storage
    ->id();
  $view_mode = $view->current_display;
  $id = Blazy::getHtmlId("slick-views-{$view_name}-{$view_mode}", $settings['id']);
  $settings += [
    'cache_metadata' => [
      'keys' => [
        $id,
        $view_mode,
        $settings['optionset'],
      ],
    ],
  ];

  // Prepare needed settings to work with.
  $settings['id'] = $id;
  $settings['item_id'] = 'slide';
  $settings['cache_tags'] = $view
    ->getCacheTags();
  $settings['caption'] = array_filter($settings['caption']);
  $settings['count'] = $count;
  $settings['current_view_mode'] = $view_mode;
  $settings['namespace'] = 'slick';
  $settings['nav'] = !$settings['vanilla'] && $settings['optionset_thumbnail'] && isset($view->result[1]);
  $settings['overridables'] = empty($settings['override']) ? array_filter($settings['overridables']) : $settings['overridables'];
  $settings['view_name'] = $view_name;
  $elements = [];
  foreach ($this
    ->renderGrouping($view->result, $settings['grouping']) as $rows) {
    $build = $this
      ->buildElements($settings, $rows);

    // Supports Blazy formatter multi-breakpoint images if available.
    if (empty($settings['vanilla'])) {
      $this
        ->blazyManager()
        ->isBlazy($settings, $build['items'][0]);
    }
    $build['settings'] = $settings;
    $elements = $this->manager
      ->build($build);
    unset($build);
  }
  return $elements;
}