protected function ReferencedEntitiesReindexingTest::createEntitiesFromMap in Search API 8
Creates a list of entities with the given fields.
Parameters
array[] $entity_fields: Map of entities to create. It should be keyed by a machine-friendly name. Values of this map should be sub-arrays that represent raw values to supply into the entity's fields when creating it.
\Drupal\Core\Entity\ContentEntityInterface[] $references_map: There is a magical field "entity_reference" in the $map input argument. Values of this field should reference some other entity. This "other" entity will be looked up by the key in this references map. This way you can create entity reference data without knowing the entity IDs ahead of time.
string $bundle: Bundle to utilize when creating entities from the $map array.
Return value
\Drupal\Core\Entity\ContentEntityInterface[] Entities created according to the supplied $map array. This array will be keyed by the same machine-names as the input $map argument.
2 calls to ReferencedEntitiesReindexingTest::createEntitiesFromMap()
- ReferencedEntitiesReindexingTest::testReferencedEntityChanged in tests/
src/ Kernel/ Datasource/ ReferencedEntitiesReindexingTest.php - Tests correct tracking of changes in referenced entities.
- ReferencedEntitiesReindexingTest::testUnrelatedDatasourceUnaffected in tests/
src/ Kernel/ Datasource/ ReferencedEntitiesReindexingTest.php - Tests whether relationships are correctly separated between datasources.
File
- tests/
src/ Kernel/ Datasource/ ReferencedEntitiesReindexingTest.php, line 285
Class
- ReferencedEntitiesReindexingTest
- Tests that changes in related entities are correctly tracked.
Namespace
Drupal\Tests\search_api\Kernel\DatasourceCode
protected function createEntitiesFromMap(array $entity_fields, array $references_map, string $bundle) : array {
$entities = [];
foreach ($entity_fields as $i => $fields) {
$reference_fields = [
'entity_reference',
'parent_reference',
];
foreach ($reference_fields as $reference_field) {
if (isset($fields[$reference_field])) {
$fields[$reference_field] = $references_map[$fields[$reference_field]]
->id();
}
}
$fields['type'] = $bundle;
$entities[$i] = Node::create($fields);
$entities[$i]
->save();
}
return $entities;
}