You are here

class views_plugin_row_node_view_split in Views nodes split 7

Same name and namespace in other branches
  1. 6 plugins/views_plugin_row_node_view_split.inc \views_plugin_row_node_view_split

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.

Hierarchy

Expanded class hierarchy of views_plugin_row_node_view_split

1 string reference to 'views_plugin_row_node_view_split'
views_nodes_split_views_plugins in ./views_nodes_split.module
Implements hook_views_plugins().

File

plugins/views_plugin_row_node_view_split.inc, line 14
Contains the node row plugin.

View source
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']['view_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 = $this
      ->options_form_summary_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']['view_mode'] = array(
      '#type' => 'select',
      '#options' => $options,
      '#title' => t('View mode'),
      '#default_value' => $this->options['first_settings']['view_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 summary_title() {
    $options = $this
      ->options_form_summary_options();
    return check_plain($options[$this->options['view_mode']] . ', ' . $options[$this->options['first_settings']['view_mode']]);
  }
  function render($row) {

    // Some static variables that help us to identify at which result index
    // are we in the current result set.
    static $keys, $current_page, $items_per_page;

    // If the static variables are not yet set, time to set them now.
    if (!isset($keys)) {
      $keys = array_keys($this->nodes);
    }
    if (!isset($current_page)) {
      $current_page = $this->view
        ->get_current_page();
    }
    if (!isset($items_per_page)) {
      $items_per_page = $this->view
        ->get_items_per_page();
    }
    $node = $this->nodes[$row->{$this->field_alias}];
    $node->view = $this->view;

    // The position of the node depends on the page we currently are and
    // on the offset inside the current page.
    $absolute_position = $current_page * $items_per_page + array_search($node->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'];
      $build = node_view($node, $this->options['first_settings']['view_mode']);
    }
    else {
      $build = node_view($node, $this->options['view_mode']);
    }

    // Check if we have to unset the links or set/unset the comments.
    // Prevent the comment form from showing up if this is not a page display.
    if ($options['view_mode'] == 'full' && !$this->view->display_handler
      ->has_path()) {
      $node->comment = FALSE;
    }
    if (!$options['links']) {
      unset($build['links']);
    }
    if (!empty($options['comments']) && user_access('access comments') && $node->comment) {
      $build['comments'] = comment_node_page_additions($node);
    }
    return drupal_render($build);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
views_object::$definition public property Handler's definition.
views_object::$options public property Except for displays, options for the object will be held here. 1
views_object::altered_option_definition function Collect this handler's option definition and alter them, ready for use.
views_object::construct public function Views handlers use a special construct function. 4
views_object::destroy public function Destructor. 2
views_object::export_option public function 1
views_object::export_options public function
views_object::export_option_always public function Always exports the option, regardless of the default value.
views_object::options Deprecated public function Set default options on this object. 1
views_object::set_default_options public function Set default options.
views_object::set_definition public function Let the handler know what its full definition is.
views_object::unpack_options public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable public function Unpack a single option definition.
views_object::unpack_translatables public function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults public function
views_plugin::$display public property The current used views display.
views_plugin::$plugin_name public property The plugin name of this plugin, for example table or full.
views_plugin::$plugin_type public property The plugin type of this plugin, for example style or query.
views_plugin::$view public property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions public function Provide a list of additional theme functions for the theme info page.
views_plugin::plugin_title public function Return the human readable name of the display.
views_plugin::theme_functions public function Provide a full list of possible theme templates used by this style.
views_plugin::validate public function Validate that the plugin is correct and can be saved. 3
views_plugin_row::options_submit public function Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data. Overrides views_plugin::options_submit 1
views_plugin_row::options_validate public function Validate the options form. Overrides views_plugin::options_validate
views_plugin_row::query public function Add anything to the query that we might need to. Overrides views_plugin::query
views_plugin_row::uses_fields public function
views_plugin_row_node_view::$base_field public property
views_plugin_row_node_view::$base_table public property Basic properties that let the row style follow relationships.
views_plugin_row_node_view::$nodes public property Stores the nodes loaded with pre_render.
views_plugin_row_node_view::init public function Overrides views_plugin_row::init
views_plugin_row_node_view::options_form_summary_options public function Return the main options, which are shown in the summary title.
views_plugin_row_node_view::pre_render public function Allow the style to do stuff before each row is rendered. Overrides views_plugin_row::pre_render
views_plugin_row_node_view_split::options_form function Provide a form for setting options. Overrides views_plugin_row_node_view::options_form
views_plugin_row_node_view_split::option_definition function Information about options for all kinds of purposes will be held here. Overrides views_plugin_row_node_view::option_definition
views_plugin_row_node_view_split::render function Render a row object. This usually passes through to a theme template of some form, but not always. Overrides views_plugin_row_node_view::render
views_plugin_row_node_view_split::summary_title function Returns the summary of the settings in the display. Overrides views_plugin_row_node_view::summary_title