Search API: Custom processor not hitting addFieldValues
EDIT
I created an issue on the search API issue queue Custom Entity Reference processor does not trigger addFieldValues()* and the maintainer has pointed to an existing issue that it was duplicating. So there is an existing issue that is being worked on here - #2910638: Entity reference via processor sample code not working Jump on there and help test :)


I couldn't post the first link because of a lack of reputation and I figured the link to the issue where work is being carried out is more useful :D


I'm encountering the same behaviour and have an idea why this occurs but not an answer on how to fix it (I can't post a comment so needed to add this as an answer).

\Drupal\search_api\Item\Item::getFields is responsible for calling the instances' implementation of addFieldValues. Within that function there is this code block:

   foreach ($this-&gt;index-&gt;getFieldsByDatasource($datasource_id) as $field_id =&gt; $field) {
      // Don't overwrite fields that were previously set.
      if (empty($this-&gt;fields[$field_id])) {
        $this-&gt;fields[$field_id] = clone $field;

        $field_data_type = $this-&gt;fields[$field_id]-&gt;getType();
        // If the field data type is in the fallback mapping list, then use
        // the fallback type as field type.
        if (isset($data_type_fallback_mapping[$field_data_type])) {
          $this-&gt;fields[$field_id]-&gt;setType($data_type_fallback_mapping[$field_data_type]);
        }

        $property = $field-&gt;getDataDefinition();
        if ($property instanceof ProcessorPropertyInterface) {
          $processors_with_fields[$property-&gt;getProcessorId()] = TRUE;
        }
        elseif ($datasource_id) {
          $fields_by_property_path[$field-&gt;getPropertyPath()][] = $this-&gt;fields[$field_id];
        }
      }
    }
    try {
      if ($fields_by_property_path) {
        \Drupal::getContainer()
          -&gt;get('search_api.fields_helper')
          -&gt;extractFields($this-&gt;getOriginalObject(), $fields_by_property_path, $this-&gt;getLanguage());
      }
      if ($processors_with_fields) {
        $processors = $this-&gt;index-&gt;getProcessorsByStage(ProcessorInterface::STAGE_ADD_PROPERTIES);
        foreach ($processors as $processor_id =&gt; $processor) {
          if (isset($processors_with_fields[$processor_id])) {
            $processor-&gt;addFieldValues($this);
          }
        }
      }
    }


If the value of $property is not an instanceof ProcessorPropertyInterface then addFieldValues() is never called.

What I'm not sure of is what is the best path to take to begin solving this.


Should I add a new custom processor that only acts on this custom field and use addFieldValues() there? (I've yet to test this) OR
Is it an issue that addFieldValues() is never called and the Search API module needs to be updated so that it is?


I've tried implementing the other functions from the parent class (\Drupal\search_api\Processor\ProcessorPluginBase) ie alterIndexedItems but none of those are triggered.

I came across the same approach that you're using here on d.o - Adding an entity reference via a processor so it may be the docs need to be updated.