// Assign random weight.
do { $weight =
mt_rand(0,
$this->fieldTestData->field_storage_2->
getCardinality());
} while (in_array($weight,
$weights_2));
$weights_2[$delta] =
$weight;
$values_2[$delta]['_weight'
] =
$weight;
} // Leave an empty value. 'field_test' fields are empty if empty().
$values_2[1
]['value'
] = 0;
// Pretend the form has been built.
$form_state->
setFormObject(\Drupal::
entityTypeManager()->
getFormObject($entity_type, 'default'
));
\Drupal::
formBuilder()->
prepareForm('field_test_entity_form',
$form,
$form_state);
\Drupal::
formBuilder()->
processForm('field_test_entity_form',
$form,
$form_state);
$form_state->
setValue($this->fieldTestData->field_name,
$values);
$form_state->
setValue($this->fieldTestData->field_name_2,
$values_2);
// Extract values for all fields.
$entity =
clone($entity_init);
$display->
extractFormValues($entity,
$form,
$form_state);
asort($weights);
asort($weights_2);