/** * Extracts value and original type from a single piece of data. * * @param \Drupal\Core\TypedData\TypedDataInterface $data * The piece of data from which to extract information. * @param \Drupal\search_api\Item\FieldInterface $field * The field into which to put the extracted data. */ public static function extractField(TypedDataInterface $data, FieldInterface $field) { $values = static::extractFieldValues($data); // If the data type of the field is a custom one, then the value can be // altered by the data type plugin. $data_type_manager = \Drupal::service('plugin.manager.search_api.data_type'); if ($data_type_manager->hasDefinition($field->getType())) { /** @var \Drupal\search_api\DataType\DataTypeInterface $data_type_plugin */ $data_type_plugin = $data_type_manager->createInstance($field->getType()); foreach ($values as $i => $value) { $values[$i] = $data_type_plugin->getValue($value); } } $field->setValues($values); $field->setOriginalType($data->getDataDefinition()->getDataType()); }