public function TestItemsTrait::createSingleFieldItem in Search API 8
Creates an array with a single item which has the given field.
Parameters
\Drupal\search_api\IndexInterface $index: The index that should be used for the item.
string $fieldType: The field type to set for the field.
mixed $fieldValue: A field value to add to the field.
\Drupal\search_api\Item\FieldInterface $field: (optional) A variable, passed by reference, into which the created field will be saved.
string $fieldId: (optional) The field ID to set for the field.
Return value
\Drupal\search_api\Item\ItemInterface[] An array containing a single item with the specified field.
File
- tests/
src/ Unit/ Processor/ TestItemsTrait.php, line 55
Class
- TestItemsTrait
- Provides common methods for test cases that need to create search items.
Namespace
Drupal\Tests\search_api\Unit\ProcessorCode
public function createSingleFieldItem(IndexInterface $index, $fieldType, $fieldValue, FieldInterface &$field = NULL, $fieldId = 'field_test') {
$this->itemIds[0] = $itemId = Utility::createCombinedId('entity:node', '1:en');
$item = new Item($index, $itemId);
$field = new Field($index, $fieldId);
$field
->setType($fieldType);
$field
->addValue($fieldValue);
$item
->setField($fieldId, $field);
$item
->setFieldsExtracted(TRUE);
return [
$itemId => $item,
];
}