diff --git a/src/Processor/ProcessorPluginBase.php b/src/Processor/ProcessorPluginBase.php index 1cfab67..db715d8 100644 --- a/src/Processor/ProcessorPluginBase.php +++ b/src/Processor/ProcessorPluginBase.php @@ -217,26 +217,28 @@ protected function filterForPropertyPath(array $fields, $property_path) { * put under in the return value. * @param bool $load * (optional) If FALSE, only field values already present will be returned. - * Otherwise, fields will be loaded if necessary. + * Otherwise, fields will be extracted (and underlying objects loaded) if + * necessary. * * @return mixed[][][] * Arrays of field values, keyed by items' indexes in $items and the given * field IDs from $required_properties. */ protected function extractItemValues(array $items, array $required_properties, $load = TRUE) { - $ret = array(); + $extracted_values = array(); foreach ($items as $i => $item) { - $property_values = array(); + $item_values = array(); /** @var \Drupal\search_api\Item\FieldInterface[][] $missing_fields */ $missing_fields = array(); $processor_fields = array(); $needed_processors = array(); foreach (array(NULL, $item->getDatasourceId()) as $datasource_id) { - $properties = $this->index->getPropertyDefinitions($datasource_id); if (empty($required_properties[$datasource_id])) { continue; } + + $properties = $this->index->getPropertyDefinitions($datasource_id); foreach ($required_properties[$datasource_id] as $property_path => $combined_id) { // If a field with the right property path is already set on the item, // use it. This might actually make problems in case the values have @@ -245,13 +247,13 @@ protected function extractItemValues(array $items, array $required_properties, $ // problem in most situations. foreach ($this->filterForPropertyPath($item->getFields(FALSE), $property_path) as $field) { if ($field->getDatasourceId() === $datasource_id) { - $property_values[$combined_id] = $field->getValues(); + $item_values[$combined_id] = $field->getValues(); continue 2; } } - // Field/property value is not present on the item. Stop here if we - // don't want to load anything. + // There are no values present on the item for this property. If we + // don't want to extract any fields, skip it. if (!$load) { continue; } @@ -276,7 +278,7 @@ protected function extractItemValues(array $items, array $required_properties, $ } else { // Extracting properties without a datasource is pointless. - $property_values[$combined_id] = array(); + $item_values[$combined_id] = array(); } } } @@ -284,7 +286,7 @@ protected function extractItemValues(array $items, array $required_properties, $ Utility::extractFields($item->getOriginalObject(), $missing_fields); foreach ($missing_fields as $property_fields) { foreach ($property_fields as $field) { - $property_values[$field->getFieldIdentifier()] = $field->getValues(); + $item_values[$field->getFieldIdentifier()] = $field->getValues(); } } } @@ -299,14 +301,14 @@ protected function extractItemValues(array $items, array $required_properties, $ } } foreach ($processor_fields as $field) { - $property_values[$field->getFieldIdentifier()] = $field->getValues(); + $item_values[$field->getFieldIdentifier()] = $field->getValues(); } } - $ret[$i] = $property_values; + $extracted_values[$i] = $item_values; } - return $ret; + return $extracted_values; } /**