You are here

public function CSV::buildConfigurationForm in Search API Synonym 8

Plugin configuration form.

Parameters

array $form: Form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state array.

Return value

array Form array.

Overrides ImportPluginBase::buildConfigurationForm

File

src/Plugin/search_api_synonym/import/CSV.php, line 56

Class

CSV
Import of CSV files.

Namespace

Drupal\search_api_synonym\Plugin\search_api_synonym\import

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $example_url = 'internal:' . base_path() . drupal_get_path('module', 'search_api_synonym') . '/examples/example.csv';
  $form['template'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Example'),
    '#markup' => Link::fromTextAndUrl(t('Download example file'), Url::fromUri($example_url))
      ->toString(),
  ];
  $form['delimiter'] = [
    '#type' => 'select',
    '#title' => t('Delimiter'),
    '#description' => t('Field delimiter character used in the import file.'),
    '#options' => [
      ';' => $this
        ->t('Semicolon'),
      ',' => $this
        ->t('Comma'),
      '\\t' => $this
        ->t('Tab'),
      '|' => $this
        ->t('Pipe'),
    ],
    '#default_value' => ';',
    '#required' => TRUE,
  ];
  $form['enclosure'] = [
    '#type' => 'select',
    '#title' => t('Text qualifier'),
    '#description' => t('Field enclosure character used in import file.'),
    '#options' => [
      '"' => '"',
      "'" => "'",
      '' => $this
        ->t('None'),
    ],
    '#default_value' => '"',
  ];
  $form['header_row'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Header row'),
    '#description' => $this
      ->t('Does the file contain a header row that should be skipped in the import?'),
    '#default_value' => FALSE,
  ];
  return $form;
}