You are here

function search_api_synonym_update_8002 in Search API Synonym 8

Remove extra white spaces from synonyms.

File

./search_api_synonym.install, line 27
Contains search_api_synonym.install.

Code

function search_api_synonym_update_8002() {
  $sids = \Drupal::entityQuery('search_api_synonym')
    ->condition('synonyms', '% %', 'LIKE')
    ->execute();
  foreach ($sids as $sid) {
    $synonym = Synonym::load($sid);
    $synonyms = explode(',', $synonym
      ->getSynonyms());
    array_walk($synonyms, 'trim');
    $synonyms = implode(',', $synonyms);
    $synonym
      ->setSynonyms($synonyms);
    $synonym
      ->save();
  }
}