You are here

public function SliderPro::render in Slider Pro 8

Render the display in this style.

Overrides StylePluginBase::render

File

src/Plugin/views/style/SliderPro.php, line 379

Class

SliderPro
Plugin annotation @ViewsStyle( id = "slider_pro", title = @Translation("Slider Pro"), help = @Translation("Displays a view as a Slider Pro, using the Slider Pro jQuery plugin."), theme = "slider_pro_views_style", theme_file =…

Namespace

Drupal\slider_pro\Plugin\views\style

Code

public function render() {
  $rows = [];
  $fields = array_keys($this
    ->getAvailableFields());
  for ($i = 0; $i < count($this->view->result); $i++) {
    $rows[$i]['layers'] = [];
    for ($j = 0; $j < count($fields); $j++) {
      $field = $fields[$j];
      $rendered_field = $this->view->style_plugin
        ->getField($i, $field);
      if (in_array($field, array_filter($this->options['fields']))) {
        $rows[$i]['slide'][$fields[$j]] = $rendered_field;
      }
      if (in_array($field, array_filter($this->options['thumbnail_fields']))) {
        $rows[$i]['thumb'][$fields[$j]] = $rendered_field;
      }
      $layers = array_slice($this->options['layers'], 0, $this->options['number_of_layers']);
      foreach ($layers as $key => $layer) {
        if (!isset($rows[$i]['layers'][$key])) {
          $rows[$i]['layers'][$key] = $layer;
        }
        if (in_array($field, array_filter($layer['fields']))) {
          $rows[$i]['layers'][$key]['content'][$fields[$j]] = $rendered_field;
        }
      }
    }
  }

  // Unset fields from all layers. Don't need it while rendering.
  foreach ($rows as &$row) {
    foreach ($row['layers'] as &$layer) {
      unset($layer['fields']);
      unset($layer['weight']);
      unset($layer['remove']);
    }
  }
  $build = array(
    '#theme' => $this
      ->themeFunctions(),
    '#view' => $this->view,
    '#options' => $this->options,
    '#rows' => $rows,
  );
  return $build;
}