You are here

public function RestrictedNameProcessor::addFieldValues in Open Social 8.9

Same name and namespace in other branches
  1. 8.7 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::addFieldValues()
  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::addFieldValues()
  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::addFieldValues()
  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::addFieldValues()
  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::addFieldValues()
  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::addFieldValues()

Adds the values of properties defined by this processor to the item.

Parameters

\Drupal\search_api\Item\ItemInterface $item: The item whose field values should be added.

Overrides ProcessorPluginBase::addFieldValues

File

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

Class

RestrictedNameProcessor
The RestrictedNameProcessor adds the restricted name to search indexes.

Namespace

Drupal\social_profile_privacy\Plugin\search_api\processor

Code

public function addFieldValues(ItemInterface $item) {
  $restricted_name = NULL;
  $nickname = $this
    ->getFirstItemField($item, 'field_profile_nick_name');

  // If the user specified a nickname then we will default to using it as
  // restricted name.
  if ($nickname !== '') {
    $restricted_name = $nickname;
  }
  else {
    $first_name = $this
      ->getFirstItemField($item, 'field_profile_first_name');
    $last_name = $this
      ->getFirstItemField($item, 'field_profile_last_name');
    $full_name = trim($first_name . ' ' . $last_name);
    if ($full_name !== '') {
      $restricted_name = $full_name;
    }
  }

  // If we have a restricted name we add it as a value for all of our
  // restricted name fields.
  if ($restricted_name) {
    $fields = $this
      ->getFieldsHelper()
      ->filterForPropertyPath($item
      ->getFields(), $item
      ->getDatasourceId(), 'social_profile_privacy_restricted_name');
    foreach ($fields as $field) {
      $field
        ->addValue($restricted_name);
    }
  }
}