function views_field_view_handler_field_view::render in Views Field View 7
Same name and namespace in other branches
- 6 views_field_view_handler_field_view.inc \views_field_view_handler_field_view::render()
Render the field.
Parameters
array $values: The values retrieved from the database.
Overrides views_handler_field::render
File
- ./
views_field_view_handler_field_view.inc, line 387 - Views field view field handler class.
Class
- views_field_view_handler_field_view
- @file Views field view field handler class.
Code
function render($values) {
static $running = array();
$output = NULL;
// If it's not a field handler and there are no values
// Get the first result row from the view and use that.
if ($this->handler_type !== 'field' && empty($values) && isset($this->view->result)) {
$values = reset($this->view->result);
}
if (empty($this->options['arguments']) && isset($this->cached[$this->options['view']][$this->options['display']])) {
// If there are no arguments, and we already cached this view, then
// our work here is done.
$output = $this->cached[$this->options['view']][$this->options['display']];
}
elseif (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();
// Only perform this loop if there are actually arguments present.
if (!empty($this->options['arguments'])) {
// Create array of tokens.
foreach ($this
->split_tokens($this->options['arguments']) as $token) {
$args[] = $this
->get_token_value($token, $values, $this->view);
}
}
// get view etc… and execute.
$view = views_get_view($this->options['view']);
// Only execute and render the view if the user has access.
if ($view
->access($this->options['display'])) {
$view
->set_display($this->options['display']);
if ($view->display_handler
->use_pager()) {
// Check whether the pager IDs should be rewritten.
$view
->init_query();
// Find a proper start value for the ascening pager IDs.
$start = 0;
$pager = $view->display_handler
->get_option('pager');
if (isset($this->query->pager->options['id'])) {
$start = (int) $this->query->pager->options['id'];
}
// Set the index at 1, as we will always want this to be atleast
// 1 higher than the start ID.
$index = 1;
// Set the pager ID before initializing the pager, so
// views_plugin_pager::set_current_page works as expected, which is
// called from view::init_pager(). There wont always be a row_index
// set so test for this.
if (isset($this->view->row_index)) {
$index += $this->view->row_index;
}
$pager['options']['id'] = $start + $index;
$view->display_handler
->set_option('pager', $pager);
$view
->init_pager();
}
$view
->pre_execute($args);
$view
->execute();
// If there are no results and hide_empty is set.
if (empty($view->result) && $this->options['hide_empty']) {
$output = '';
}
else {
$output = $view
->render();
}
}
$running[$this->options['view']][$this->options['display']] = FALSE;
}
elseif ($this->child_view && $this->options['view'] && $this->options['query_aggregation']) {
$running[$this->options['view']][$this->options['display']] = TRUE;
$child_view = $this->child_view;
// Only execute and render the view if the user has access.
if ($child_view
->access($this->options['display'])) {
$results = $this->child_view_results[$values->{$this->view->base_field}];
// If there are no results and hide_empty is set.
if (empty($results) && $this->options['hide_empty']) {
$output = '';
}
else {
// 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);
}
$child_view
->pre_execute();
$output = $child_view
->render();
}
$running[$this->options['view']][$this->options['display']] = FALSE;
}
}
}
else {
$output = t('Recursion, stop!');
}
if (empty($this->options['arguments']) && !isset($this->cached[$this->options['view']][$this->options['display']])) {
// If there are no arguments and no existing static cache then set a
// static cache for this view.
$this->cached[$this->options['view']][$this->options['display']] = $output;
}
// We only add the output to the $values object for field handlers. Area
// handlers will not use this.
if ($this->handler_type == 'field' && !empty($output)) {
// Add the rendered output back to the $values object so it is available
// in $view->result objects.
$values->{'views_field_view_' . $this->options['id']} = $output;
}
return $output;
}