You are here

public function FieldGroupTable::settingsForm in Field Group Table 8

File

src/Plugin/field_group/FieldGroupFormatter/FieldGroupTable.php, line 161

Class

FieldGroupTable
Plugin implementation of the 'field_group_table' formatter.

Namespace

Drupal\field_group_table\Plugin\field_group\FieldGroupFormatter

Code

public function settingsForm() {
  $form = parent::settingsForm();
  $form['label_visibility'] = [
    '#title' => $this
      ->t('Label visibility'),
    '#description' => $this
      ->t('This option determines how to display the Field group label.'),
    '#type' => 'select',
    '#options' => [
      self::DISPLAY_HIDDEN => $this
        ->t('Hidden'),
      self::DISPLAY_ABOVE => $this
        ->t('Above table'),
      self::DISPLAY_CAPTION => $this
        ->t('Table caption'),
      self::DISPLAY_BELOW => $this
        ->t('Below table'),
    ],
    '#default_value' => $this
      ->getSetting('label_visibility'),
  ];
  $form['desc'] = [
    '#title' => $this
      ->t('Description for the group.'),
    '#type' => 'textarea',
    '#default_value' => $this
      ->getSetting('desc'),
  ];
  $form['desc_visibility'] = [
    '#title' => $this
      ->t('Description visibility'),
    '#description' => $this
      ->t('This option determines how to display the Field group description.'),
    '#type' => 'select',
    '#options' => [
      self::DISPLAY_HIDDEN => $this
        ->t('Hidden'),
      self::DISPLAY_ABOVE => $this
        ->t('Above table'),
      self::DISPLAY_BELOW => $this
        ->t('Below table'),
    ],
    '#default_value' => $this
      ->getSetting('desc_visibility'),
  ];
  $form['first_column'] = [
    '#title' => $this
      ->t('First column header'),
    '#description' => $this
      ->t('Use this field to add a first column table header.'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('first_column'),
  ];
  $form['second_column'] = [
    '#title' => $this
      ->t('Second column header'),
    '#description' => $this
      ->t('Use this field to add a second column table header.'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('second_column'),
  ];
  $form['empty_label_behavior'] = [
    '#title' => $this
      ->t('Empty label behavior'),
    '#type' => 'select',
    '#options' => [
      self::EMPTY_LABEL_KEEP => $this
        ->t('Keep empty label cell'),
      self::EMPTY_LABEL_MERGE => $this
        ->t('Merge cells'),
    ],
    '#default_value' => $this
      ->getSetting('empty_label_behavior'),
  ];
  $form['table_row_striping'] = [
    '#title' => $this
      ->t('Table row striping'),
    '#description' => $this
      ->t('Adds zebra striping on the table rows.'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('table_row_striping'),
  ];
  $form['always_show_field_label'] = [
    '#title' => $this
      ->t('Always show field label'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('always_show_field_label'),
  ];
  $form['always_show_field_value'] = [
    '#title' => $this
      ->t('Always show field value'),
    '#description' => $this
      ->t('Forces row to display even if field have an empty value.'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('always_show_field_value'),
    '#attributes' => [
      'class' => [
        'fgt-always-show-field-value',
      ],
    ],
  ];
  $form['empty_field_placeholder'] = [
    '#title' => $this
      ->t('Empty field placeholder'),
    '#description' => $this
      ->t('What to display as a content of empty field.'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('empty_field_placeholder'),
    '#states' => [
      'visible' => [
        '.fgt-always-show-field-value' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['hide_table_if_empty'] = [
    '#title' => $this
      ->t('Hide the table if empty'),
    '#description' => $this
      ->t('Do not output any table or container markup if there are no rows with values.'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('hide_table_if_empty'),
  ];
  switch ($this->context) {
    case 'view':
      $form['always_show_field_label']['#description'] = $this
        ->t('Forces the field label to always display in the first column and renders the field normally with label display option which was selected for current display.<br>Set Label display "Above" or "Hidden" to hide field label in second column.');
      break;
    case 'form':
      $form['always_show_field_label']['#description'] = $this
        ->t('Forces to duplicate field label in a second column.');
      break;
  }
  return $form;
}