protected function PhotosImageSearch::parseAdvancedDefaults in Album Photos 8.5
Same name and namespace in other branches
- 6.0.x src/Plugin/Search/PhotosImageSearch.php \Drupal\photos\Plugin\Search\PhotosImageSearch::parseAdvancedDefaults()
Parses the advanced search form default values.
Parameters
array $f: The 'f' query parameter set up in self::buildUrlSearchQuery(), which contains the advanced query values.
string $keys: The search keywords string, which contains some information from the advanced search form.
Return value
array Array of default form values for the advanced search form, including a modified 'keys' element for the bare search keywords.
1 call to PhotosImageSearch::parseAdvancedDefaults()
- PhotosImageSearch::searchFormAlter in src/
Plugin/ Search/ PhotosImageSearch.php - Alters the search form when being built for a given plugin.
File
- src/
Plugin/ Search/ PhotosImageSearch.php, line 778
Class
- PhotosImageSearch
- Handles searching for photos_image entities using the Search module index.
Namespace
Drupal\photos\Plugin\SearchCode
protected function parseAdvancedDefaults(array $f, $keys) {
$defaults = [];
// Split out the advanced search parameters.
foreach ($f as $advanced) {
[
$key,
$value,
] = explode(':', $advanced, 2);
if (!isset($defaults[$key])) {
$defaults[$key] = [];
}
$defaults[$key][] = $value;
}
// Split out the negative, phrase, and OR parts of keywords.
// For phrases, the form only supports one phrase.
$matches = [];
$keys = ' ' . $keys . ' ';
if (preg_match('/ "([^"]+)" /', $keys, $matches)) {
$keys = str_replace($matches[0], ' ', $keys);
$defaults['phrase'] = $matches[1];
}
// Negative keywords: pull all of them out.
if (preg_match_all('/ -([^ ]+)/', $keys, $matches)) {
$keys = str_replace($matches[0], ' ', $keys);
$defaults['negative'] = implode(' ', $matches[1]);
}
// OR keywords: pull up to one set of them out of the query.
if (preg_match('/ [^ ]+( OR [^ ]+)+ /', $keys, $matches)) {
$keys = str_replace($matches[0], ' ', $keys);
$words = explode(' OR ', trim($matches[0]));
$defaults['or'] = implode(' ', $words);
}
// Put remaining keywords string back into keywords.
$defaults['keys'] = trim($keys);
return $defaults;
}