You are here

public function SearchApiGlossaryAZProcessor::addFieldValues in Search API AZ Glossary 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/search_api/processor/SearchApiGlossaryAZProcessor.php \Drupal\search_api_glossary\Plugin\search_api\processor\SearchApiGlossaryAZProcessor::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

src/Plugin/search_api/processor/SearchApiGlossaryAZProcessor.php, line 61

Class

SearchApiGlossaryAZProcessor
Adds the item's AZ to the indexed data.

Namespace

Drupal\search_api_glossary\Plugin\search_api\processor

Code

public function addFieldValues(ItemInterface $item) {

  // Load up config and loop though settings.
  if ($config = \Drupal::config('search_api_glossary.settings')) {
    $search_api_glossary_settings = $config
      ->get();
    $item_fields = $item
      ->getFields();

    // Loop through all fields.
    foreach ($item_fields as $field_name => $field_values) {
      if (array_key_exists($field_name, $search_api_glossary_settings) && $search_api_glossary_settings[$field_name]['enabled'] == 1 && !empty($field_values
        ->getValues())) {
        $source_field_value = $field_values
          ->getValues()[0];

        // Glossary process.
        $glossary_value = SearchApiGlossaryAZHelper::glossaryGetter($source_field_value, $search_api_glossary_settings[$field_name]['glossary_az_grouping']);
        $target_field_id = $search_api_glossary_settings[$field_name]['glossary_field_id'];

        // Set the Target Glossary value.
        if (empty($item
          ->getField($target_field_id)
          ->getValues())) {
          $item
            ->getField($target_field_id)
            ->addValue($glossary_value);
        }
      }
    }
  }
}