diff --git a/src/Plugin/views/field/SearchApiFieldTrait.php b/src/Plugin/views/field/SearchApiFieldTrait.php index 525ecb0..28c8546 100644 --- a/src/Plugin/views/field/SearchApiFieldTrait.php +++ b/src/Plugin/views/field/SearchApiFieldTrait.php @@ -317,9 +317,7 @@ public function preRender(&$values) { // Now go through all rows and add the property to them, if necessary. foreach ($values as $i => $row) { - // Bail for rows with the wrong datasource for this property, or for - // which this field doesn't even apply (which will usually be the - // same, though). + // Check whether this field even exists for this row. if (!$this->isActiveForRow($row)) { continue; } @@ -366,17 +364,34 @@ public function preRender(&$values) { if (!$parent_path && isset($definitions[$name])) { $definition = $definitions[$name]; if ($definition instanceof ProcessorPropertyInterface) { - // We need to run any relevant processors in order to get the - // field value. We do this using a clone of the search item - // so as to preserve the state of the original item. + $processor = $index->getProcessor($definition->getProcessorId()); + if (!$processor) { + continue; + } + // We need to call the processor's addFieldValues() method in + // order to get the field value. We do this using a clone of + // the search item so as to preserve the original state of the + // item. We also use a dummy field object – either a clone of + // a fitting indexed field (to get its configuration), or a + // newly created one. + $property_fields = \Drupal::getContainer() + ->get('search_api.fields_helper') + ->filterForPropertyPath($index->getFields(), $datasource_id, $property_path); + if ($property_fields) { + $dummy_field = clone reset($property_fields); + } + else { + $dummy_field = Utility::createFieldFromProperty($index, $definition, $datasource_id, $property_path, 'tmp', 'string'); + } /** @var \Drupal\search_api\Item\ItemInterface $dummy_item */ $dummy_item = clone $row->_item; - $dummy_field = clone $dummy_item->getField($property_path); + $dummy_item->setFields(array( + 'tmp' => $dummy_field, + )); $dummy_item->setFieldsExtracted(TRUE); - $processors = $index->getProcessorsByStage(ProcessorInterface::STAGE_ADD_PROPERTIES); - foreach ($processors as $processor_id => $processor) { - $processor->addFieldValues($dummy_item); - } + + $processor->addFieldValues($dummy_item); + if ($set_values) { $row->{$combined_property_path} = array(); } @@ -388,6 +403,7 @@ public function preRender(&$values) { ->create($definition, $value); $row->_relationship_objects[$property_path][] = $typed_data; } + continue; } }