You are here

function panels_views_plugin_row_fields::render in Panels 7.3

Same name and namespace in other branches
  1. 6.3 plugins/views/panels_views_plugin_row_fields.inc \panels_views_plugin_row_fields::render()

Render a row object. This usually passes through to a theme template of some form, but not always.

Overrides views_plugin_row::render

File

plugins/views/panels_views_plugin_row_fields.inc, line 86
Contains the base row style plugin.

Class

panels_views_plugin_row_fields
The basic 'fields' row plugin.

Code

function render($row) {
  ctools_include('plugins', 'panels');
  $layout = panels_get_layout($this->options['layout']);
  if (!$layout) {

    // Fall back to normal behavior if the layout is somehow invalid. This
    // can happen if the layout was removed, for example.
    return theme($this
      ->theme_functions(), array(
      'view' => $this->view,
      'options' => $this->options,
      'row' => $row,
    ));
  }

  // Store a backup copy of the array because we're going to be screwing
  // with this a lot.
  $fields = $this->view->field;
  unset($this->view->field);
  $meta = 'standard';

  // This row style gets run many times; only run this code once.
  if (empty($this->region_fields)) {
    $this->region_fields = array();
    $regions = panels_get_regions($layout, panels_new_display());

    // Ensure each region has an empty array.
    foreach ($regions as $region_id => $name) {
      if (empty($default_region)) {
        $default_region = $region_id;
      }
      $this->region_fields[$region_id] = array();
    }

    // Go through all our fields and place them in regions according to the
    // settings.
    foreach ($fields as $id => $field) {
      $region_id = '';

      // ensure we don't accidentlly use the last field's region.
      if (!empty($this->options['regions'][$id]) && !empty($regions[$this->options['regions'][$id]])) {
        $region_id = $this->options['regions'][$id];
      }
      else {

        // Fallback to putting unknown fields into the first region.
        $region_id = $default_region;
      }

      // Ensure this works in PHP4 by keeping the reference.
      $this->region_fields[$region_id][$id] =& $fields[$id];
    }

    // We don't need to set 'inline' for every record, so we do it inside
    // this loop. We do need to set inline if we are in the live preview
    // so that the CSS will get transmitted via javascript:
    $meta = !empty($this->view->live_preview) ? 'inline' : 'standard';
  }

  // Now that we have distributed our fields, go through the regions and
  // render them into the content array.
  foreach ($this->region_fields as $region_id => $fields_list) {
    $this->view->field = $fields_list;
    $content[$region_id] = theme($this
      ->theme_functions(), array(
      'view' => $this->view,
      'options' => $this->options,
      'row' => $row,
    ));
  }

  // Restore our $fields array.
  $this->view->field = $fields;

  // Now that we have a rendered content array, render it.
  return panels_print_layout($layout, $content, $meta);
}