public function Importer::createSynonyms in Search API Synonym 8
Create synonyms.
Parameters
array $items: Raw synonyms data.
array $settings: Import settings.
Return value
array Array with info about the result.
1 call to Importer::createSynonyms()
- Importer::execute in src/
Import/ Importer.php - Execute the import of an array with synonyms.
File
- src/
Import/ Importer.php, line 124
Class
- Importer
- Importer class.
Namespace
Drupal\search_api_synonym\ImportCode
public function createSynonyms(array $items, array $settings) {
$context = [];
// Import with batch.
$operations = [];
foreach ($items as $type => $item) {
// Continue with next item if type is not valid.
if ($type == 'empty') {
$context['results']['errors'][] = [
'word' => key($item),
'synonyms' => current($item),
];
continue;
}
// Add each item to the batch.
foreach ($item as $word => $synonyms) {
$operations[] = [
'\\Drupal\\search_api_synonym\\Import\\Importer::createSynonym',
[
$word,
$synonyms,
$type,
$settings,
],
];
}
}
$batch = [
'title' => t('Import synonyms...'),
'operations' => $operations,
'finished' => '\\Drupal\\search_api_synonym\\Import\\Importer::createSynonymBatchFinishedCallback',
];
batch_set($batch);
return isset($context['results']) ? $context['results'] : NULL;
}