EntityFieldExport.php in REST Views 2.0.x
File
src/Plugin/views/field/EntityFieldExport.php
View source
<?php
namespace Drupal\rest_views\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\rest_views\SerializedData;
use Drupal\views\Plugin\views\field\EntityField;
class EntityFieldExport extends EntityField {
public function renderItems($items) {
if (!empty($items)) {
$items = $this
->prepareItemsByDelta($items);
foreach ($items as $i => $item) {
if (is_array($items[$i])) {
$items[$i] = $this->renderer
->render($item);
}
}
$data = $this->multiple ? $items : reset($items);
}
else {
$data = $this->multiple ? [] : NULL;
}
return SerializedData::create($data);
}
public function render_item($count, $item) {
$rendered = $item['rendered'];
if (isset($rendered['#type']) && $rendered['#type'] === 'data') {
return $rendered['#data'];
}
return parent::render_item($count, $item);
}
public function renderText($alter) {
if (isset($this->last_render) && $this->last_render instanceof SerializedData) {
return $this->last_render;
}
return parent::renderText($alter);
}
public function multiple_options_form(&$form, FormStateInterface $form_state) : void {
$this->options['multi_type'] = $this->options['separator'] = NULL;
parent::multiple_options_form($form, $form_state);
unset($form['multi_type'], $form['separator'], $this->options['multi_type'], $this->options['separator']);
}
public function defineOptions() : array {
$options = parent::defineOptions();
unset($options['multi_type'], $options['separator']);
return $options;
}
}