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']; } }