You are here

public function views_php_handler_field::render in Views PHP 7

Same name and namespace in other branches
  1. 6 plugins/views/views_php_handler_field.inc \views_php_handler_field::render()
  2. 7.2 plugins/views/views_php_handler_field.inc \views_php_handler_field::render()

Implements views_handler_field#render().

Overrides views_handler_field::render

File

plugins/views/views_php_handler_field.inc, line 213

Class

views_php_handler_field
A handler to provide a field that is constructed by the administrator using PHP.

Code

public function render($values) {

  // Execute output PHP code.
  if (!empty($this->options['php_output'])) {
    $normalized_row = new stdClass();
    foreach ($this->view->display_handler
      ->get_handlers('field') as $field => $handler) {
      $normalized_row->{$field} = isset($values->{$handler->field_alias}) ? $values->{$handler->field_alias} : NULL;
    }
    $code = ' ?>' . $this->options['php_output'];
    $function = function ($view, $handler, &$static, $row, $data, $value) use ($code) {
      eval($code);
    };
    ob_start();
    $function($this->view, $this, $this->php_static_variable, $normalized_row, $values, isset($values->{$this->field_alias}) ? $values->{$this->field_alias} : NULL);
    $value = ob_get_clean();
  }
  else {
    if (isset($values->{$this->field_alias})) {
      $value = check_plain($values->{$this->field_alias});
    }
  }
  if (isset($value)) {
    return $value;
  }
}