X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fsearch_api_synonym%2Fsrc%2FPlugin%2Fsearch_api_synonym%2Fimport%2FCSV.php;fp=web%2Fmodules%2Fcontrib%2Fsearch_api_synonym%2Fsrc%2FPlugin%2Fsearch_api_synonym%2Fimport%2FCSV.php;h=31da97b2e04627a7d7e859a50baa0fd4a74f7c96;hp=0000000000000000000000000000000000000000;hb=4e1bfbf98b844da83b18aca92ef00f11a4735806;hpb=f3baf763d342a5f82576890e2a8111a5aaf139dc diff --git a/web/modules/contrib/search_api_synonym/src/Plugin/search_api_synonym/import/CSV.php b/web/modules/contrib/search_api_synonym/src/Plugin/search_api_synonym/import/CSV.php new file mode 100644 index 000000000..31da97b2e --- /dev/null +++ b/web/modules/contrib/search_api_synonym/src/Plugin/search_api_synonym/import/CSV.php @@ -0,0 +1,110 @@ +getFileUri(), 'r')) !== FALSE) { + while (($row = fgetcsv($handle, 1000, $delimiter, $enclosure)) !== FALSE) { + if ($header_row && $i++ == 1) { + continue; + } + + if (!empty($row[0]) && !empty($row[1])) { + $data[] = [ + 'word' => $row[0], + 'synonym' => $row['1'], + 'type' => !empty($row['2']) ? $row['2'] : '' + ]; + } + } + fclose($handle); + } + + return $data; + } + + /** + * {@inheritdoc} + */ + 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; + } + + /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + $values = $form_state->getValues(); + } + + /** + * {@inheritdoc} + */ + public function allowedExtensions() { + return ['csv txt']; + } + +}