You are here

views_plugin_row_node_view_split.inc in Views nodes split 6

Same filename and directory in other branches
  1. 7 plugins/views_plugin_row_node_view_split.inc

Contains the node row plugin.

File

plugins/views_plugin_row_node_view_split.inc
View source
<?php

/**
 * @file
 *   Contains the node row plugin.
 */

// @todo: can we get rid of these?
require_once './' . drupal_get_path('module', 'views') . '/plugins/views_plugin_row.inc';
require_once './' . drupal_get_path('module', 'views') . '/modules/node/views_plugin_row_node_view.inc';

/**
 * Plugin which performs a node_view on the resulting object.
 *
 * The difference between this plugin and the core node row plugin is that it
 * can display the first nodes with a different view module.
 */
class views_plugin_row_node_view_split extends views_plugin_row_node_view {
  function option_definition() {
    $options = parent::option_definition();

    // Adds some new options.
    $options['first_settings']['build_mode'] = array(
      'default' => 'teaser',
    );
    $options['first_settings']['links'] = array(
      'default' => TRUE,
    );
    $options['first_settings']['comments'] = array(
      'default' => FALSE,
    );
    $options['first_settings']['first_x_value'] = array(
      'default' => 0,
    );
    return $options;
  }
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $options = $form['build_mode']['#options'];
    $form['first_settings'] = array(
      '#type' => 'fieldset',
      '#title' => t('Split settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['first_settings']['first_x_value'] = array(
      '#type' => 'textfield',
      '#title' => t('Split limit'),
      '#description' => t('The results that are situated before or at this limit will have a different view mode.'),
      '#default_value' => $this->options['first_settings']['first_x_value'],
    );
    $form['first_settings']['build_mode'] = array(
      '#type' => 'select',
      '#options' => $options,
      '#title' => t('Build mode'),
      '#default_value' => $this->options['first_settings']['build_mode'],
    );
    $form['first_settings']['links'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display links'),
      '#default_value' => $this->options['first_settings']['links'],
    );
    $form['first_settings']['comments'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display comments'),
      '#default_value' => $this->options['first_settings']['comments'],
    );
  }
  function render($row) {

    // A static variable to keep an array with the whole result set.
    static $keys;

    // If the static variable is not yet set, time to set it now.
    if (!isset($keys)) {
      foreach ($this->view->result as $result_object) {
        $keys[] = $result_object->nid;
      }
    }

    // The position of the node depends on the page we currently are and
    // on the offset inside the current page.
    $absolute_position = $this->view->pager['current_page'] * $this->view->pager['item_per_page'] + array_search($row->nid, $keys) + 1;

    // Because we can have two view modes settings, we will store in the
    // the $options array the correct set of options for this row (links and
    // comments).
    $options = $this->options;

    // And now we check which view mode we should display.
    if ($absolute_position <= $this->options['first_settings']['first_x_value']) {

      // If we display the other view mode, also update the display settings.
      $options = $this->options['first_settings'];
    }
    return theme($this
      ->theme_functions(), $this->view, $options, $row, $this->field_alias);
  }

}

Classes

Namesort descending Description
views_plugin_row_node_view_split Plugin which performs a node_view on the resulting object.