1. 8.5.x core/modules/views/src/Plugin/views/display/EntityReference.php
  2. 8.5.x core/modules/entity_reference/src/Plugin/views/style/EntityReference.php
  3. 8.5.x core/modules/views/src/Plugin/views/row/EntityReference.php
  4. 8.5.x core/modules/views/src/Plugin/views/style/EntityReference.php
  5. 8.5.x core/lib/Drupal/Core/Field/Plugin/migrate/field/d7/EntityReference.php
  6. 8.5.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php
  7. 8.5.x core/modules/entity_reference/src/Plugin/views/display/EntityReference.php
  8. 8.5.x core/modules/entity_reference/src/Plugin/views/row/EntityReference.php
  9. 8.0.x core/modules/entity_reference/src/Plugin/views/row/EntityReference.php
  10. 8.0.x core/modules/entity_reference/src/Plugin/views/display/EntityReference.php
  11. 8.0.x core/modules/entity_reference/src/Plugin/views/style/EntityReference.php
  12. 8.0.x core/modules/views/src/Plugin/views/display/EntityReference.php
  13. 8.0.x core/modules/views/src/Plugin/views/style/EntityReference.php
  14. 8.0.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php
  15. 8.0.x core/modules/views/src/Plugin/views/row/EntityReference.php
  16. 8.1.x core/modules/views/src/Plugin/views/style/EntityReference.php
  17. 8.1.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php
  18. 8.1.x core/modules/views/src/Plugin/views/display/EntityReference.php
  19. 8.1.x core/modules/entity_reference/src/Plugin/views/row/EntityReference.php
  20. 8.1.x core/modules/views/src/Plugin/views/row/EntityReference.php
  21. 8.1.x core/modules/entity_reference/src/Plugin/views/display/EntityReference.php
  22. 8.1.x core/modules/entity_reference/src/Plugin/views/style/EntityReference.php
  23. 8.2.x core/modules/entity_reference/src/Plugin/views/display/EntityReference.php
  24. 8.2.x core/modules/entity_reference/src/Plugin/views/row/EntityReference.php
  25. 8.2.x core/modules/entity_reference/src/Plugin/views/style/EntityReference.php
  26. 8.2.x core/modules/views/src/Plugin/views/style/EntityReference.php
  27. 8.2.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php
  28. 8.2.x core/modules/views/src/Plugin/views/display/EntityReference.php
  29. 8.2.x core/modules/views/src/Plugin/views/row/EntityReference.php
  30. 8.3.x core/modules/views/src/Plugin/views/display/EntityReference.php
  31. 8.3.x core/modules/views/src/Plugin/views/row/EntityReference.php
  32. 8.3.x core/modules/entity_reference/src/Plugin/views/row/EntityReference.php
  33. 8.3.x core/modules/entity_reference/src/Plugin/views/display/EntityReference.php
  34. 8.3.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php
  35. 8.3.x core/modules/views/src/Plugin/views/style/EntityReference.php
  36. 8.3.x core/modules/entity_reference/src/Plugin/views/style/EntityReference.php
  37. 8.4.x core/modules/views/src/Plugin/views/row/EntityReference.php
  38. 8.4.x core/modules/views/src/Plugin/views/display/EntityReference.php
  39. 8.4.x core/modules/entity_reference/src/Plugin/views/display/EntityReference.php
  40. 8.4.x core/modules/entity_reference/src/Plugin/views/row/EntityReference.php
  41. 8.4.x core/modules/entity_reference/src/Plugin/views/style/EntityReference.php
  42. 8.4.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php
  43. 8.4.x core/lib/Drupal/Core/Field/Plugin/migrate/field/d7/EntityReference.php
  44. 8.4.x core/modules/views/src/Plugin/views/style/EntityReference.php
  45. 8.6.x core/modules/views/src/Plugin/views/row/EntityReference.php
  46. 8.6.x core/lib/Drupal/Core/Field/Plugin/migrate/field/d7/EntityReference.php
  47. 8.6.x core/modules/views/src/Plugin/views/display/EntityReference.php
  48. 8.6.x core/modules/views/src/Plugin/views/style/EntityReference.php
  49. 8.6.x core/modules/entity_reference/src/Plugin/views/row/EntityReference.php
  50. 8.6.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php
  51. 8.6.x core/modules/entity_reference/src/Plugin/views/display/EntityReference.php
  52. 8.6.x core/modules/entity_reference/src/Plugin/views/style/EntityReference.php

Namespace

Drupal\views\Plugin\views\style

File

core/modules/views/src/Plugin/views/style/EntityReference.php
View source
<?php

namespace Drupal\views\Plugin\views\style;

use Drupal\Component\Utility\Xss;
use Drupal\Core\Form\FormStateInterface;

/**
 * EntityReference style plugin.
 *
 * @ingroup views_style_plugins
 *
 * @ViewsStyle(
 *   id = "entity_reference",
 *   title = @Translation("Entity Reference list"),
 *   help = @Translation("Returns results as a PHP array of labels and rendered rows."),
 *   theme = "views_view_unformatted",
 *   register_theme = FALSE,
 *   display_types = {"entity_reference"}
 * )
 */
class EntityReference extends StylePluginBase {

  /**
   * {@inheritdoc}
   */
  protected $usesRowPlugin = TRUE;

  /**
   * {@inheritdoc}
   */
  protected $usesFields = TRUE;

  /**
   * {@inheritdoc}
   */
  protected $usesGrouping = FALSE;

  /**
   * {@inheritdoc}
   */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['search_fields'] = array(
      'default' => array(),
    );
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    $options = $this->displayHandler
      ->getFieldLabels(TRUE);
    $form['search_fields'] = array(
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Search fields'),
      '#options' => $options,
      '#required' => TRUE,
      '#default_value' => $this->options['search_fields'],
      '#description' => $this
        ->t('Select the field(s) that will be searched when using the autocomplete widget.'),
      '#weight' => -3,
    );
  }

  /**
   * {@inheritdoc}
   */
  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) {
        $results[$values->{$id_field_alias}] = $this->view->rowPlugin
          ->render($values);

        // Sanitize HTML, remove line breaks and extra whitespace.
        $results[$values->{$id_field_alias}]['#post_render'][] = function ($html, array $elements) {
          return Xss::filterAdmin(preg_replace('/\\s\\s+/', ' ', str_replace("\n", '', $html)));
        };
      }
    }
    return $results;
  }

  /**
   * {@inheritdoc}
   */
  public function evenEmpty() {
    return TRUE;
  }

}

Classes

Namesort descending Description
EntityReference EntityReference style plugin.