public function CSV::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/ CSV.php, line 26
Class
- CSV
- Import of CSV files.
Namespace
Drupal\search_api_synonym\Plugin\search_api_synonym\importCode
public function parseFile(File $file, array $settings = []) {
$data = [];
$delimiter = $settings['delimiter'];
$enclosure = $settings['enclosure'];
$header_row = $settings['header_row'];
$i = 1;
if (($handle = fopen($file
->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;
}