3 namespace Drupal\search_api_synonym\Plugin\search_api_synonym\import;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\file\Entity\File;
9 use Drupal\search_api_synonym\Import\ImportPluginBase;
10 use Drupal\search_api_synonym\Import\ImportPluginInterface;
13 * Import of Solr synonyms.txt files.
15 * @SearchApiSynonymImport(
17 * label = @Translation("Solr"),
18 * description = @Translation("Synonym import plugin from Solr synonyms.txt file.")
21 class Solr extends ImportPluginBase implements ImportPluginInterface {
26 public function parseFile(File $file, array $settings = []) {
30 $rows = file($file->getFileUri());
32 if (is_array($rows)) {
33 foreach ($rows as $row) {
37 if (empty($row) || substr($row, 0, 1) == '#') {
41 $parts = explode('=>', $row);
44 if (count($parts) == 2) {
46 'word' => trim($parts[0]),
47 'synonym' => trim($parts['1']),
48 'type' => 'spelling_error'
54 'word' => trim(substr($row, 0, strpos($row, ','))),
55 'synonym' => trim(substr($row, strpos($row, ',') + 1)),
68 public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
69 $example_url = 'internal:' . base_path() . drupal_get_path('module', 'search_api_synonym') . '/examples/solr_synonyms.txt';
72 '#title' => $this->t('Example'),
73 '#markup' => Link::fromTextAndUrl(t('Download example file'), Url::fromUri($example_url))->toString()
81 public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
87 public function allowedExtensions() {