You are here

public function RestrictedNameProcessor::preprocessSearchQuery in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_profile/modules/social_profile_privacy/src/Plugin/search_api/processor/RestrictedNameProcessor.php \Drupal\social_profile_privacy\Plugin\search_api\processor\RestrictedNameProcessor::preprocessSearchQuery()
  2. 8.8 modules/social_features/social_profile/modules/social_profile_privacy/src/Plugin/search_api/processor/RestrictedNameProcessor.php \Drupal\social_profile_privacy\Plugin\search_api\processor\RestrictedNameProcessor::preprocessSearchQuery()
  3. 10.3.x modules/social_features/social_profile/modules/social_profile_privacy/src/Plugin/search_api/processor/RestrictedNameProcessor.php \Drupal\social_profile_privacy\Plugin\search_api\processor\RestrictedNameProcessor::preprocessSearchQuery()
  4. 10.0.x modules/social_features/social_profile/modules/social_profile_privacy/src/Plugin/search_api/processor/RestrictedNameProcessor.php \Drupal\social_profile_privacy\Plugin\search_api\processor\RestrictedNameProcessor::preprocessSearchQuery()
  5. 10.1.x modules/social_features/social_profile/modules/social_profile_privacy/src/Plugin/search_api/processor/RestrictedNameProcessor.php \Drupal\social_profile_privacy\Plugin\search_api\processor\RestrictedNameProcessor::preprocessSearchQuery()
  6. 10.2.x modules/social_features/social_profile/modules/social_profile_privacy/src/Plugin/search_api/processor/RestrictedNameProcessor.php \Drupal\social_profile_privacy\Plugin\search_api\processor\RestrictedNameProcessor::preprocessSearchQuery()

Preprocesses a search query.

Parameters

\Drupal\search_api\Query\QueryInterface $query: The object representing the query to be executed.

Overrides ProcessorPluginBase::preprocessSearchQuery

File

modules/social_features/social_profile/modules/social_profile_privacy/src/Plugin/search_api/processor/RestrictedNameProcessor.php, line 129

Class

RestrictedNameProcessor
The RestrictedNameProcessor adds the restricted name to search indexes.

Namespace

Drupal\social_profile_privacy\Plugin\search_api\processor

Code

public function preprocessSearchQuery(QueryInterface $query) {
  $config = \Drupal::config('social_profile_privacy.settings');
  $account = \Drupal::currentUser();

  // If the use of real names is not limited or the user can bypass this
  // restriction then we're done too.
  if (!$config
    ->get('limit_search_and_mention') || $account
    ->hasPermission('social profile privacy always show full name')) {
    return;
  }

  // Get all fields available to search in.
  $all_fields = $query
    ->getFulltextFields() ?? $query
    ->getIndex()
    ->getFulltextFields();

  // Remove the first name and last name from the search query, if a user has
  // no nickname, this value will be searchable through
  // social_profile_privacy_restricted_name. If a user has a nickname then the
  // first and last name is not searchable.
  $search_fields = array_diff($all_fields, [
    'field_profile_first_name',
    'field_profile_last_name',
  ]);
  $query
    ->setFulltextFields($search_fields);
}