+
+ // 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;
+
+ // Mark the sample entity as being a preview.
+ $values['entity'] = $entity_storage->createWithSampleValues($bundle, ['in_preview' => TRUE]);
+
+ // Remove the indicator once the entity is successfully generated.
+ unset($recursion_tracker[$key]);