You are here

public function EntityReferenceRevisions::render in Entity Reference Revisions 8

Same name in this branch
  1. 8 src/Plugin/views/display/EntityReferenceRevisions.php \Drupal\entity_reference_revisions\Plugin\views\display\EntityReferenceRevisions::render()
  2. 8 src/Plugin/views/style/EntityReferenceRevisions.php \Drupal\entity_reference_revisions\Plugin\views\style\EntityReferenceRevisions::render()

Overrides \Drupal\views\Plugin\views\style\StylePluginBase\StylePluginBase::render().

Overrides StylePluginBase::render

File

src/Plugin/views/style/EntityReferenceRevisions.php, line 71

Class

EntityReferenceRevisions
EntityReferenceRevisions style plugin.

Namespace

Drupal\entity_reference_revisions\Plugin\views\style

Code

public function render() {
  if (!empty($this->view->live_preview)) {
    return parent::render();
  }

  // Group the rows according to the grouping field, if specified.
  $sets = $this
    ->renderGrouping($this->view->result, $this->options['grouping']);

  // Grab the alias of the 'id' field added by
  // entity_reference_plugin_display.
  $id_field_alias = $this->view->storage
    ->get('base_field');

  // @todo We don't display grouping info for now. Could be useful for select
  // widget, though.
  $results = array();
  foreach ($sets as $records) {
    foreach ($records as $values) {

      // Sanitize HTML, remove line breaks and extra whitespace.
      $output = $this->view->rowPlugin
        ->render($values);
      $output = \Drupal::service('renderer')
        ->render($output);
      $results[$values->{$id_field_alias}] = Xss::filterAdmin(preg_replace('/\\s\\s+/', ' ', str_replace("\n", '', $output)));
    }
  }
  return $results;
}