You are here

public function OptionsBase::buildExportOptionsForm in YAML Form 8

Get an element's export options form.

Parameters

array $form: An associative array containing the structure of the form.

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

array $export_options: An associative array of default values.

Return value

array An associative array contain an element's export option form.

Overrides YamlFormElementBase::buildExportOptionsForm

File

src/Plugin/YamlFormElement/OptionsBase.php, line 314

Class

OptionsBase
Provides a base 'options' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function buildExportOptionsForm(array &$form, FormStateInterface $form_state, array $export_options) {
  if (isset($form['options'])) {
    return;
  }
  $form['options'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Select menu, radio buttons, and checkboxes options'),
    '#open' => TRUE,
    '#weight' => -10,
  ];
  $form['options']['options_format'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Options format'),
    '#options' => [
      'compact' => $this
        ->t('Compact; with the option values delimited by commas in one column.') . '<div class="description">' . $this
        ->t('Compact options are more suitable for importing data into other systems.') . '</div>',
      'separate' => $this
        ->t('Separate; with each possible option value in its own column.') . '<div class="description">' . $this
        ->t('Separate options are more suitable for building reports, graphs, and statistics in a spreadsheet application. Ranking will be included for sortable option elements.') . '</div>',
    ],
    '#default_value' => $export_options['options_format'],
  ];
  $form['options']['options_item_format'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Options item format'),
    '#options' => [
      'label' => $this
        ->t('Option labels, the human-readable value (label)'),
      'key' => $this
        ->t('Option values, the raw value stored in the database (key)'),
    ],
    '#default_value' => $export_options['options_item_format'],
  ];
}