You are here

public function CallbackFieldRow::render in Search Autocomplete 8

Same name and namespace in other branches
  1. 2.x src/Plugin/views/row/CallbackFieldRow.php \Drupal\search_autocomplete\Plugin\views\row\CallbackFieldRow::render()

Overrides \Drupal\views\Plugin\views\row\RowPluginBase::render().

Overrides RowPluginBase::render

File

src/Plugin/views/row/CallbackFieldRow.php, line 150

Class

CallbackFieldRow
Plugin which displays fields as raw data.

Namespace

Drupal\search_autocomplete\Plugin\views\row

Code

public function render($row) {
  $output = [];

  // Render all fields.
  foreach ($this->view->field as $id => $field) {

    // If this is not unknown and the raw output option has been set, just get
    // the raw value.
    if ($field->field_alias != 'unknown' && !empty($this->rawOutputOptions[$id])) {
      $value = $field
        ->sanitizeValue($field
        ->getValue($row), 'xss_admin');
    }
    else {
      if (!isset($this->view->row_index) || $this->view->row_index == NULL) {
        $this->view->row_index = $row->row_index;
      }
      $value = $field
        ->advancedRender($row);
    }

    // Add input link.
    if (isset($this->rowOptions['input_link']) && $this->rowOptions['input_link'] == $id) {
      $output['link'] = $value;
    }

    // Add value link.
    if (isset($this->rowOptions['input_label']) && $this->rowOptions['input_label'] == $id) {
      $output['value'] = $value;
    }

    // Add label if defined.
    if ($field->options['label']) {
      $value = $field->options['label'] . ': ' . $value;
    }

    // If field is not excluded: include in response.
    if (!$field->options['exclude']) {
      $output['fields'][$this
        ->getFieldKeyAlias($id)] = $value;
    }
  }
  return $output;
}