You are here

class EntityReference in Drupal 10

Same name in this branch
  1. 10 core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php \Drupal\Core\Entity\Plugin\DataType\EntityReference
  2. 10 core/modules/views/src/Plugin/views/style/EntityReference.php \Drupal\views\Plugin\views\style\EntityReference
  3. 10 core/modules/views/src/Plugin/views/row/EntityReference.php \Drupal\views\Plugin\views\row\EntityReference
  4. 10 core/modules/field/src/Plugin/migrate/field/d7/EntityReference.php \Drupal\field\Plugin\migrate\field\d7\EntityReference
Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/row/EntityReference.php \Drupal\views\Plugin\views\row\EntityReference
  2. 9 core/modules/views/src/Plugin/views/row/EntityReference.php \Drupal\views\Plugin\views\row\EntityReference

EntityReference row plugin.

Plugin annotation


@ViewsRow(
  id = "entity_reference",
  title = @Translation("Entity Reference inline fields"),
  help = @Translation("Displays the fields with an optional template."),
  theme = "views_view_fields",
  register_theme = FALSE,
  display_types = {"entity_reference"}
)

Hierarchy

  • class \Drupal\views\Plugin\views\row\Fields extends \Drupal\views\Plugin\views\row\RowPluginBase

Expanded class hierarchy of EntityReference

2 string references to 'EntityReference'
views.view.test_entity_reference.yml in core/modules/system/tests/modules/entity_reference_test/config/install/views.view.test_entity_reference.yml
core/modules/system/tests/modules/entity_reference_test/config/install/views.view.test_entity_reference.yml
views.view.test_entity_reference_entity_test.yml in core/modules/system/tests/modules/entity_reference_test/config/install/views.view.test_entity_reference_entity_test.yml
core/modules/system/tests/modules/entity_reference_test/config/install/views.view.test_entity_reference_entity_test.yml

File

core/modules/views/src/Plugin/views/row/EntityReference.php, line 21

Namespace

Drupal\views\Plugin\views\row
View source
class EntityReference extends Fields {

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

  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);

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

  /**
   * {@inheritdoc}
   */
  public function preRender($row) {

    // Force all fields to be inline by default.
    if (empty($this->options['inline'])) {
      $fields = $this->view
        ->getHandlers('field', $this->displayHandler->display['id']);
      $names = array_keys($fields);
      $this->options['inline'] = array_combine($names, $names);
    }
    return parent::preRender($row);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityReference::buildOptionsForm public function Provide a form for setting options. Overrides Fields::buildOptionsForm
EntityReference::defineOptions protected function Overrides Fields::defineOptions
EntityReference::preRender public function
Fields::$usesFields protected property Does the row plugin support to add fields to its output.
Fields::submitOptionsForm public function Perform any necessary changes to the form values prior to storage.