EntityReference.php 1.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php

/**
 * @file
 * Contains \Drupal\entity_reference\Plugin\views\row\EntityReference.
 */

namespace Drupal\entity_reference\Plugin\views\row;

use Drupal\views\Plugin\views\row\Fields;

/**
 * EntityReference row plugin.
 *
 * @ingroup views_row_plugins
 *
17
 * @ViewsRow(
18 19 20 21
 *   id = "entity_reference",
 *   title = @Translation("Entity Reference inline fields"),
 *   help = @Translation("Displays the fields with an optional template."),
 *   theme = "views_view_fields",
22
 *   register_theme = FALSE,
23
 *   display_types = {"entity_reference"}
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
 * )
 */
class EntityReference extends Fields {

  /**
   * Overrides \Drupal\views\Plugin\views\row\Fields::defineOptions().
   */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['separator'] = array('default' => '-');

    return $options;
  }

  /**
   * Overrides \Drupal\views\Plugin\views\row\Fields::buildOptionsForm().
   */
  public function buildOptionsForm(&$form, &$form_state) {
    parent::buildOptionsForm($form, $form_state);

    // Expand the description of the 'Inline field' checkboxes.
    $form['inline']['#description'] .= '<br />' . t("<strong>Note:</strong> In 'Entity Reference' displays, all fields will be displayed inline unless an explicit selection of inline fields is made here." );
  }

  /**
49
   * {@inheritdoc}
50
   */
51
  public function preRender($row) {
52 53
    // Force all fields to be inline by default.
    if (empty($this->options['inline'])) {
54
      $fields = $this->view->getHandlers('field', $this->displayHandler->display['id']);
55 56
      $names = array_keys($fields);
      $this->options['inline'] = array_combine($names, $names);
57 58
    }

59
    return parent::preRender($row);
60 61
  }
}