You are here

public function SlickViews::render in Slick Views 7.2

Renders the display in this style.

Overrides views_plugin_style::render

File

./SlickViews.inc, line 83
Slick style plugin for the Views module.

Class

SlickViews
Implements a style type plugin for the Views module.

Code

public function render() {
  global $language;
  $langcode = isset($language->language) ? $language->language : LANGUAGE_NONE;
  $view = $this->view;
  $settings = $this->options;
  $view_name = $view->name;
  $current = $view->current_display;
  $id = slick_html_id("slick-views-{$view_name}", $settings['id']);
  $thumb_id = $id . '-thumbnail';
  $asnavfor = $settings['optionset_thumbnail'];
  $attach = $build = array();

  // Renders slicks quickly from cache if any, as render cache is just cache.
  $settings['count'] = count($view->result);
  $settings['nav'] = $asnavfor && $settings['count'] > 1;
  $settings['cid'] = $settings['optionset'] . $settings['skin'] . $view_name . $current . $langcode;
  if (!empty($settings['cache']) && ($cache = slick_render_cache($settings))) {
    return $this
      ->renderSlick($cache, $settings);
  }

  // Otherwise do the routines before a cache stored, or when disabled.
  module_load_include('inc', 'slick', 'includes/slick.global');
  $optionset = slick_optionset_load($settings['optionset']);
  $optionset_thumbnail = !$settings['nav'] ? NULL : slick_optionset_load($asnavfor);
  $attachments = slick_attach($attach, $settings);
  $lazy = $optionset->options['settings']['lazyLoad'];
  $settings['blazy'] = $lazy == 'blazy' || !empty($settings['breakpoints']);
  $settings['lazy'] = $settings['blazy'] ? 'blazy' : $lazy;
  $settings['has_pattern'] = !empty($optionset->options['general']['goodies']['pattern']);
  $settings['view_name'] = $view_name;
  $settings['current_view_mode'] = $current;
  $settings['current_display'] = 'main';
  $settings['ratio'] = !empty($settings['aspect_ratio']) ? $settings['aspect_ratio'] : FALSE;
  $build = array();
  foreach ($this
    ->render_grouping($view->result, $settings['grouping']) as $rows) {
    $js = array();
    if ($settings['nav']) {
      $js['asNavFor'] = "#{$thumb_id}-slider";
    }

    // Build the single/main display Slick.
    $items = $this
      ->buildElements($rows, $settings);
    $slick[0] = slick_build($items, $js, $settings, $attachments, $id, $optionset);
    if (empty($items) && !$view->use_ajax) {

      // Return empty $build if there are no results.
      // Otherwise views will never show empty behaviour.
      // Important: If use_ajax is on, we can't do this, as the library may be missing then. See below.
      return $build;
    }
    elseif (empty($items) && $view->use_ajax) {

      // Warning: THIS MAY LEAD TO UNEXPECTED BEHAVIOUR, SEE https://www.drupal.org/project/slick_views/issues/3210378
      // Attach library if there is no results and ajax is active,
      // otherwise library will not be attached on ajax callback.
      $slick[0]['#attached'] = $attachments;
    }
    if ($settings['nav']) {
      $settings['optionset'] = $asnavfor;
      $settings['current_display'] = 'thumbnail';
      $js['asNavFor'] = "#{$id}-slider";

      // Build the thumbnail+/text navigation Slick.
      $thumbs = $this
        ->buildElements($rows, $settings, TRUE);
      $slick[1] = slick_build($thumbs, $js, $settings, array(), $id, $optionset_thumbnail);
      unset($thumbs, $optionset_thumbnail);
    }

    // Build the Slick.
    $build = $this
      ->renderSlick($slick, $settings);
    unset($slick, $items, $optionset, $settings, $view);
  }
  return $build;
}