// the entity.
$item =
[ 'target_id' =>
$fid,
'alt' =>
$default_langcode . '_' .
$fid . '_' .
$this->
randomMachineName(),
'title' =>
$default_langcode . '_' .
$fid . '_' .
$this->
randomMachineName(),
];
$entity->
{$this->fieldName
}[] =
$item;
// Store the generated values keying them by fid for easier lookup.
$values[$default_langcode][$fid] =
$item;
} $entity =
$this->
saveEntity($entity);
// Create some field translations for the test image field. The translated
// items will be one less than the original values to check that only the
// translated ones will be preserved. In fact we want the same fids and
// items order for both languages.
$translation =
$entity->
addTranslation($langcode);
for ($delta = 0;
$delta <
$this->cardinality - 1;
$delta++
) { // Simulate a field reordering: items are shifted of one position ahead.
// The modulo operator ensures we start from the beginning after reaching
// the maximum allowed delta.
$index =
($delta + 1
) %
$this->cardinality;