You are here

function views_ifempty_handler_field::render in Views If Empty 7

Same name and namespace in other branches
  1. 6 handlers/views_ifempty_handler_field.inc \views_ifempty_handler_field::render()

Render the output.

Overrides views_handler_field::render

File

includes/views/handlers/views_ifempty_handler_field.inc, line 120
A views handler to output an alterate field when a field is empty.

Class

views_ifempty_handler_field
@file A views handler to output an alterate field when a field is empty.

Code

function render($values) {
  $emptyfield = $this->options['emptyfield'];
  $outputfield = $this->options['outputfield'];

  // Double-check that the field has been configured properly.
  if (!empty($emptyfield) && !empty($outputfield) && $emptyfield != $outputfield) {

    // Get all the available fields.
    $fields = $this->view->display_handler
      ->get_handlers('field');
    if (isset($fields[$emptyfield]) && isset($fields[$outputfield])) {

      // Is emptyfield empty? If so, output outputfield.
      if (empty($fields[$emptyfield]->last_render)) {

        // If we've selected to reverse the behavior, output nothing.
        if ($this->options['reverse']) {
          $this->last_render = '';
        }
        else {
          $this->last_render = $fields[$outputfield]->last_render;
        }
      }
      else {

        // If we've selected to reverse the behavior, output $outputfield.
        if ($this->options['reverse']) {
          $this->last_render = $fields[$outputfield]->last_render;
        }
        else {
          $this->last_render = $fields[$emptyfield]->last_render;
        }
      }
    }
  }
  return $this->last_render;
}