src/Extension/Core/DataTransformer/EmptyValueTransformer.php
public function transform($value)
    {
        if (is_array($this->emptyValue) && !is_array($value)) {
            throw new TransformationFailedException('Empty value is an array, but provided value is not an array.');
        }

        // Note. empty is not used here as 0 is a none-empty value.
        // Only false, null and an empty string is considered empty.

        if (!is_array($value)) {
            return '' === (string) $value ? $this->emptyValue : $value;
        }

        $emptyIsString = is_string($this->emptyValue);

        foreach ($value as $field => &$val) {
            if (isset($val) && '' !== $val) {
                continue;
            }

            if ($emptyIsString) {
                $val = $this->emptyValue;
            } elseif (!array_key_exists($field, $this->emptyValue)) {
                throw new TransformationFailedException(
                    sprintf('No empty value-replacement for field "%s" set.', $field)
                );
            } else {
                $emptyValue = $this->emptyValue[$field];

                if (!is_string($emptyValue)) {
                    throw new TransformationFailedException(
                        sprintf('Empty value of field "%s" must be a string value.', $field)
                    );
                }

                $val = $emptyValue;
            }
        }

        return $value;
    }
public function transform($value)
    {
        if (is_array($this->emptyValue) && !is_array($value)) {
            throw new TransformationFailedException('Empty value is an array, but provided value is not an array.');
        }

        // Note. empty is not used here as 0 is a none-empty value.
        // Only false, null and an empty string is considered empty.

        if (!is_array($value)) {
            return '' === (string) $value ? $this->emptyValue : $value;
        }

        $emptyIsString = is_string($this->emptyValue);

        foreach ($value as $field => &$val) {
            if (isset($val) && '' !== $val) {
                continue;
            }

            if ($emptyIsString) {
                $val = $this->emptyValue;
            } elseif (!array_key_exists($field, $this->emptyValue)) {
                throw new TransformationFailedException(
                    sprintf('No empty value-replacement for field "%s" set.', $field)
                );
            } else {
                $emptyValue = $this->emptyValue[$field];

                if (!is_string($emptyValue)) {
                    throw new TransformationFailedException(
                        sprintf('Empty value of field "%s" must be a string value.', $field)
                    );
                }

                $val = $emptyValue;
            }
        }

        return $value;
    }
{@inheritdoc}