public function EntityReference::render

Same name in this branch

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

Overrides StylePluginBase::render

File

drupal/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/views/style/EntityReference.php, line 75
Contains \Drupal\entity_reference\Plugin\views\style\EntityReference.

Class

EntityReference
EntityReference style plugin.

Namespace

Drupal\entity_reference\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();
  $this->view->row_index = 0;
  foreach ($sets as $records) {
    foreach ($records as $values) {

      // Sanitize HTML, remove line breaks and extra whitespace.
      $output = $this->view->rowPlugin
        ->render($values);
      $output = drupal_render($output);
      $results[$values->{$id_field_alias}] = filter_xss_admin(preg_replace('/\\s\\s+/', ' ', str_replace("\n", '', $output)));
      $this->view->row_index++;
    }
  }
  unset($this->view->row_index);
  return $results;
}