// Select a random number of references between the last 50 referenceable
// entities created.
if ($referenceable =
$selection_handler->
getReferenceableEntities(NULL, 'CONTAINS', 50
)) { $group =
array_rand($referenceable);
$values['target_id'
] =
array_rand($referenceable[$group]);
return $values;
} // Attempt to create a sample entity, avoiding recursion.
$entity_storage = \Drupal::
entityTypeManager()->
getStorage($options['target_type'
]);
if ($entity_storage instanceof ContentEntityStorageInterface
) { $bundle =
static::
getRandomBundle($entity_type,
$options);
// Track the generated entity by reference type, target type, and bundle.
$key =
$field_definition->
getTargetEntityTypeId() . ':' .
$options['target_type'
] . ':' .
$bundle;
// If entity generation was attempted but did not finish, do not continue.
if (isset($recursion_tracker[$key])) { return [];
} // Mark this as an attempt at generation.
$recursion_tracker[$key] = TRUE;