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%2FJSON.php;fp=web%2Fmodules%2Fcontrib%2Fsearch_api_synonym%2Fsrc%2FPlugin%2Fsearch_api_synonym%2Fimport%2FJSON.php;h=58901d0ee3bd7271467efcecce53b98914207bdc;hp=0000000000000000000000000000000000000000;hb=4e1bfbf98b844da83b18aca92ef00f11a4735806;hpb=f3baf763d342a5f82576890e2a8111a5aaf139dc diff --git a/web/modules/contrib/search_api_synonym/src/Plugin/search_api_synonym/import/JSON.php b/web/modules/contrib/search_api_synonym/src/Plugin/search_api_synonym/import/JSON.php new file mode 100644 index 000000000..58901d0ee --- /dev/null +++ b/web/modules/contrib/search_api_synonym/src/Plugin/search_api_synonym/import/JSON.php @@ -0,0 +1,72 @@ +getFileUri()); + + if ($items = SerializationJSON::decode($json)) { + foreach ($items as $item) { + if (!empty($item['word']) && !empty($item['synonym'])) { + $data[] = [ + 'word' => $item['word'], + 'synonym' => $item['synonym'], + 'type' => !empty($item['type']) ? $item['type'] : '' + ]; + } + } + } + + 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.json'; + $form['template'] = [ + '#type' => 'item', + '#title' => $this->t('Example'), + '#markup' => Link::fromTextAndUrl(t('Download example file'), Url::fromUri($example_url))->toString() + ]; + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + } + + /** + * {@inheritdoc} + */ + public function allowedExtensions() { + return ['json']; + } + +}