You are here

public static function SuggestionHelper::atomize in Autocomplete Search Suggestions 8.2

Same name and namespace in other branches
  1. 8 src/SuggestionHelper.php \Drupal\suggestion\SuggestionHelper::atomize()
  2. 3.0.x src/SuggestionHelper.php \Drupal\suggestion\SuggestionHelper::atomize()

Transform a string to an array.

Parameters

string $txt: The string to process.

Return value

array An array of atoms.

2 calls to SuggestionHelper::atomize()
SuggestionHelper::insert in src/SuggestionHelper.php
Add a suggestion.
suggestion_surfer_submit in ./suggestion.module
Custom submit function to add surfer suggestions.

File

src/SuggestionHelper.php, line 67

Class

SuggestionHelper
Provides helper methods for suggestions.

Namespace

Drupal\suggestion

Code

public static function atomize($txt = '') {
  $atoms = [];
  $stopwords = self::getStops('stopwords');
  foreach (preg_split('/\\s+/', $txt) as $atom) {
    if (!empty($stopwords[$atom])) {
      continue;
    }
    $atoms[$atom] = $atom;
  }
  return $atoms;
}