You are here

public function JSON::parseFile in Search API Synonym 8

Parse the import file.

Parameters

\Drupal\file\Entity\File $file: The temporary file object.

array $settings: Array with plugin settings.

Return value

string The parsed file content.

Overrides ImportPluginBase::parseFile

File

src/Plugin/search_api_synonym/import/JSON.php, line 27

Class

JSON
Import of JSON files.

Namespace

Drupal\search_api_synonym\Plugin\search_api_synonym\import

Code

public function parseFile(File $file, array $settings = []) {
  $data = [];
  $json = file_get_contents($file
    ->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;
}