$fieldConfig) { // Keep current value if it can be resolved to "there is something" directly if (isset($databaseRow[$fieldName])) { $newRow[$fieldName] = $databaseRow[$fieldName]; continue; } // Special handling for nullable fields if ($fieldConfig['config']['nullable'] ?? false) { if (// Field exists and is set to NULL array_key_exists($fieldName, $databaseRow) // Default NULL is set, and this is a new record! || (array_key_exists('default', $fieldConfig['config']) && $fieldConfig['config']['default'] === null) ) { $newRow[$fieldName] = null; } else { $newRow[$fieldName] = (string)($fieldConfig['config']['default'] ?? ''); } } else { // Fun part: This forces empty string for any field even if no default is set. This is // a useful side effect in flex form section containers where a new field is added to an existing // value array because it was added to a data structure. $newRow[$fieldName] = (string)($fieldConfig['config']['default'] ?? ''); } } $result['databaseRow'] = $newRow; return $result; } }