You are here

public function FormatterBase::settingsForm in Reference Table Formatter 8

Returns a form to configure settings for the formatter.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form elements for the formatter settings.

Overrides FormatterBase::settingsForm

File

src/FormatterBase.php, line 82

Class

FormatterBase
A base field formatter class for rendering tables.

Namespace

Drupal\reference_table_formatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $view_modes = $this
    ->getConfigurableViewModes();
  if (!empty($view_modes)) {
    $form['view_mode'] = [
      '#title' => $this
        ->t('View Mode'),
      '#description' => $this
        ->t('Select the view mode which will control which fields are shown and the display settings of those fields.'),
      '#type' => 'select',
      '#default_value' => $this
        ->getSettings()['view_mode'],
      '#options' => $this
        ->getConfigurableViewModes(),
    ];
  }
  $form['show_entity_label'] = [
    '#title' => $this
      ->t('Display Entity Label'),
    '#description' => $this
      ->t('Should the label of the target entity be displayed in the table?'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSettings()['show_entity_label'],
  ];
  $form['hide_header'] = [
    '#title' => $this
      ->t('Hide Table Header'),
    '#description' => $this
      ->t('Should the table header be displayed?'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSettings()['hide_header'],
  ];
  $form['empty_cell_value'] = [
    '#title' => $this
      ->t('Empty Cell Value'),
    '#description' => $this
      ->t('The string which should be displayed in empty cells. Defaults to an empty string.'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSettings()['empty_cell_value'],
  ];
  return $form;
}