You are here

function views_plugin_ds_entity_view::render in Display Suite 7

Same name and namespace in other branches
  1. 7.2 views/views_plugin_ds_entity_view.inc \views_plugin_ds_entity_view::render()

Render each $row.

Overrides views_plugin_row::render

File

views/views_plugin_ds_entity_view.inc, line 285
Provides the Display suite views entity style plugin.

Class

views_plugin_ds_entity_view
Plugin which defines the view mode on the resulting entity object.

Code

function render($row) {

  // Set a variable to indicate if comments need to be loaded or not.
  $load_comments = isset($this->options['load_comments']) ? $this->options['load_comments'] : FALSE;

  // The advanced selector searches for a function called
  // ds_views_row_adv_VIEWSNAME. Return the row immediately.
  if ($this->options['advanced']) {
    $row_function = 'ds_views_row_adv_' . $this->view->name;
    if (function_exists($row_function)) {
      return $row_function($this->entities[$row->{$this->field_alias}], $this->options['view_mode'], $load_comments);
    }
  }

  // Keep a static group array.
  static $grouping = array();
  $view_name = $this->view->name . '_' . $this->view->current_display;
  $group_value_content = '';

  // Default view mode.
  $view_mode = $this->options['view_mode'];

  // Change the view mode per row.
  if ($this->options['alternating']) {

    // Check for paging to determine the view mode.
    if (isset($_GET['page']) && isset($this->options['alternating_fieldset']['allpages']) && !$this->options['alternating_fieldset']['allpages']) {
      $view_mode = $this->options['view_mode'];
    }
    else {
      $view_mode = isset($this->options['alternating_fieldset']['item_' . $this->view->row_index]) ? $this->options['alternating_fieldset']['item_' . $this->view->row_index] : $this->options['view_mode'];
    }
  }

  // Give modules a chance to alter the $view_mode. Use $view_mode by ref.
  $context = array(
    'entity' => $this->entities[$row->{$this->field_alias}],
    'view_name' => $this->view->name,
    'display' => $this->view->current_display,
  );
  drupal_alter('ds_views_view_mode', $view_mode, $context);

  // Call the row render function.
  $content = $this
    ->ds_views_row_render_entity($view_mode, $row, $load_comments);

  // Keep a static grouping for this view.
  if ($this->options['grouping']) {
    $group_field = $this->options['grouping_fieldset']['group_field'];

    // New way of creating the alias.
    if (strpos($group_field, '|') !== FALSE) {
      list($ftable, $ffield) = explode('|', $group_field);
      $group_field = $this->view->sort[$ffield]->table_alias . '_' . $this->view->sort[$ffield]->real_field;
    }

    // Note, the keys in the $row object are cut of at 60 chars.
    // see views_plugin_query_default.inc.
    if (drupal_strlen($group_field) > 60) {
      $group_field = drupal_substr($group_field, 0, 60);
    }
    $raw_group_value = isset($row->{$group_field}) ? $row->{$group_field} : '';
    if (!isset($grouping[$view_name][$raw_group_value])) {
      $group_value = $raw_group_value;

      // Special function to format the heading value.
      if (!empty($this->options['grouping_fieldset']['group_field_function'])) {
        $function = $this->options['grouping_fieldset']['group_field_function'];
        if (function_exists($function)) {
          $group_value = $function($raw_group_value, $this->entities[$row->{$this->field_alias}]);
        }
      }
      $group_value_content = '<h2 class="grouping-title">' . $group_value . '</h2>';
      $grouping[$view_name][$raw_group_value] = $raw_group_value;
    }
  }

  // Grouping.
  if (!empty($grouping[$view_name])) {
    if (!empty($group_value_content)) {
      $content = $group_value_content . $content;
    }
    $content = '<div class="grouping-content">' . $content . '</div>';
  }

  // Return the content.
  return $content;
}