+ // Store the initial value in form state. The machine name needs this to
+ // ensure that the exists function is not called for existing values when
+ // editing them.
+ $initial_values = $form_state->get('machine_name.initial_values') ?: [];
+ // Store the initial values in an array so we can differentiate between a
+ // NULL default value and a new machine name element.
+ if (!array_key_exists($element['#name'], $initial_values)) {
+ $initial_values[$element['#name']] = $element['#default_value'];
+ $form_state->set('machine_name.initial_values', $initial_values);
+ }
+