You are here

public function ViewsPhp::render in Views PHP 8

Same name in this branch
  1. 8 src/Plugin/views/area/ViewsPhp.php \Drupal\views_php\Plugin\views\area\ViewsPhp::render()
  2. 8 src/Plugin/views/field/ViewsPhp.php \Drupal\views_php\Plugin\views\field\ViewsPhp::render()

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides FieldPluginBase::render

File

src/Plugin/views/field/ViewsPhp.php, line 120
Contains \Drupal\views_php\Plugin\views\field\ViewsPhp.

Class

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

Namespace

Drupal\views_php\Plugin\views\field

Code

public function render(ResultRow $values) {
  if (!empty($this->options['php_output'])) {
    $this->php_output_lamda_function = create_function('$view, $handler, &$static, $row, $data, $value', ' ?>' . $this->options['php_output'] . '<?php ');
    $normalized_row = new ViewsPhpNormalizedRow();
    if (empty($this->view->style_plugin->rendered_fields)) {
      foreach ($this->view->field as $id => $field) {
        if ($field->field_alias != $this->field_alias) {
          $value = $field
            ->getValue($values);
          $normalized_row->{$id} = $value;
        }
      }
    }
    else {
      foreach ($this->view->style_plugin->rendered_fields[$this->view->row_index] as $field => $value) {
        $normalized_row->{$field} = $value;
      }
    }
    $function = $this->php_output_lamda_function;
    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 {
    $value = $this
      ->sanitizeValue($values->{$this->field_alias});
  }
  return $value;
}