You are here

public function EntityReferenceDisplayFormatterTrait::settingsForm in Entity Reference Display 8

File

src/Plugin/Field/FieldFormatter/EntityReferenceDisplayFormatterTrait.php, line 26

Class

EntityReferenceDisplayFormatterTrait
Plugin trait for the 'entity_reference_display' formatters.

Namespace

Drupal\entity_reference_display\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = [];

  // Get display mode fields.
  $display_fields = $this
    ->getDisplayFields();

  // Create select element.
  $element['display_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Display mode field'),
    '#description' => $this
      ->t('Select a field of which value will be used as a display mode for rendering.'),
    '#options' => $display_fields,
    '#default_value' => $this
      ->getSetting('display_field'),
    '#required' => TRUE,
    '#access' => count($display_fields) > 1,
  ];
  return $element;
}