You are here

function views_field_view_handler_field_view::render in Views Field View 6

Same name and namespace in other branches
  1. 7 views_field_view_handler_field_view.inc \views_field_view_handler_field_view::render()

File

./views_field_view_handler_field_view.inc, line 231

Class

views_field_view_handler_field_view

Code

function render($values) {
  static $running = array();

  // Protect against the evil / recursion.
  // Set the variable for yourself, this is not for the normal "user".
  if (empty($running[$this->options['view']][$this->options['display']]) || variable_get('views_field_view_evil', FALSE)) {
    if ($this->options['view'] && !$this->options['query_aggregation']) {
      $running[$this->options['view']][$this->options['display']] = TRUE;
      $args = array();
      $args[] = $this->options['view'];
      $args[] = $this->options['display'];

      // Only perform this loop if there are actually arguments present
      if (!empty($this->options['arguments'])) {
        foreach (explode(',', $this->options['arguments']) as $argument) {
          $alter = array(
            'text' => $argument,
          );
          $tokens = $this
            ->get_render_tokens($alter);
          $value = $this
            ->render_altered($alter, $tokens);
          $args[] = $value;
        }
      }
      $output = call_user_func_array('views_embed_view', $args);
      $running[$this->options['view']][$this->options['display']] = FALSE;
    }
    else {
      if ($this->child_view && $this->options['view'] && $this->options['query_aggregation']) {
        $running[$this->options['view']][$this->options['display']] = TRUE;
        $child_view = $this->child_view;
        $results = $this->child_view_results[$values->{$this->view->base_field}];

        // Inject the appropriate result set before rendering the view.
        $child_view->result = $results;
        if (isset($child_view->style_plugin->rendered_fields)) {
          unset($child_view->style_plugin->rendered_fields);
        }
        $output = $child_view
          ->render();
        $running[$this->options['view']][$this->options['display']] = FALSE;
      }
    }
  }
  else {
    $output = t('Recursion, stop!');
  }
  return $output;
}