Search API: Custom processor not hitting addFieldValues I'm creating a custom module for adding a processor that adds relative entities. Here's my code for getPropertyDefinition.

public function getPropertyDefinitions(DatasourceInterface $datasource = NULL) {
$properties = [];
if ($datasource) {
  $entity_type = \Drupal::service('entity_type.manager')-&gt;getStorage('group_type')-&gt;load(key($datasource-&gt;getBundles()));
  $entity_type_ids = [];
  $plugin_manager = \Drupal::service('plugin.manager.group_content_enabler')-&gt;getInstalled();
  foreach($plugin_manager-&gt;getInstanceIds() as $instance_id) {
    array_push($entity_type_ids, $plugin_manager-&gt;get($instance_id)-&gt;getPluginDefinition()['entity_type_id']);
  }
  foreach($entity_type_ids as $entity_type_id) {
    $definition = [
      'label' =&gt; $this-&gt;t(ucwords($entity_type_id)),
      'description' =&gt; $this-&gt;t('Entity reference of ' . $entity_type_id),
      'type' =&gt; 'entity:' . $entity_type_id,
      'processor_id' =&gt; $this-&gt;getPluginId(),
    ];
    $properties[$entity_type_id] = new EntityProcessorProperty($definition);
    $properties[$entity_type_id]-&gt;setEntityTypeId($entity_type_id);
  }
}
return $properties;
}


And, after adding relative fields to index, I think it should hit addFieldValues method but it doesn't. For test purpose, I only put die in the method.

public function addFieldValues(ItemInterface $item) {die;}


But, when I copied code from addURI's getPropertyDefinition into my getPropertyDefinition, it hits addFieldValues when indexing. Is there anything wrong in my getPropertyDefinition?
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.