EntityReference.php 1.72 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

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

namespace Drupal\entity_reference\Plugin\views\row;

10
use Drupal\views\Annotation\ViewsRow;
11 12 13 14 15 16 17 18
use Drupal\Core\Annotation\Translation;
use Drupal\views\Plugin\views\row\Fields;

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

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

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