You are here

protected function RestrictedNameProcessor::getFirstItemField in Open Social 10.1.x

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::getFirstItemField()
  2. 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::getFirstItemField()
  3. 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::getFirstItemField()
  4. 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::getFirstItemField()
  5. 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::getFirstItemField()
  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::getFirstItemField()

Fetches the first value of a field for an item.

Parameters

\Drupal\search_api\Item\ItemInterface $item: The item that the field belongs to.

string $field_name: The name of the field.

Return value

string The first value of the item or an empty string if no value could be found.

1 call to RestrictedNameProcessor::getFirstItemField()
RestrictedNameProcessor::addFieldValues in modules/social_features/social_profile/modules/social_profile_privacy/src/Plugin/search_api/processor/RestrictedNameProcessor.php

File

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

Class

RestrictedNameProcessor
The RestrictedNameProcessor adds the restricted name to search indexes.

Namespace

Drupal\social_profile_privacy\Plugin\search_api\processor

Code

protected function getFirstItemField(ItemInterface $item, string $field_name) : string {
  $field = $item
    ->getField($field_name);

  // If the field doesn't exist we default to an empty string.
  if (!$field) {
    return '';
  }
  $field_values = $field
    ->getValues();

  // If the field has no values then we convert it to an empty string.
  if (empty($field_values)) {
    return '';
  }
  return reset($field_values);
}