Repository: symfony/symfony
File: src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php (PHP)

Code before:
            // field name. We can only use numeric IDs as names, as we cannot
            // guarantee that a non-numeric ID contains a valid form name
            if ($options['id_reader'] instanceof IdReader && $options['id_reader']->isIntId()) {
                return ChoiceList::fieldName($this, [__CLASS__, 'createChoiceName']);
            }

            // Otherwise, an incrementing integer is used as name automatically
            return null;
        };

        // The choices are always indexed by ID (see "choices" normalizer
        // and DoctrineChoiceLoader), unless the ID is composite. Then they
        // are indexed by an incrementing integer.
        // Use the ID/incrementing integer as choice value.
        $choiceValue = function (Options $options) {
            // If the entity has a single-column ID, use that ID as value
            if ($options['id_reader'] instanceof IdReader && $options['id_reader']->isSingleId()) {
                $idReader = $options['id_reader'];
                $uidFormat = $options['uid_format'];

                if (null !== $uidFormat) {
                    $formatMethod = 'to'.ucfirst($uidFormat);
                    $callback = static function (?object $object = null) use ($idReader, $formatMethod): string {
                        $value = $idReader->getIdValue($object);

                        if ('' === $value) {
                            return '';
                        }

                        return Uuid::fromString($value)->$formatMethod();
                    };

                    return ChoiceList::value($this, $callback, [$idReader, $uidFormat]);
                }

                return ChoiceList::value($this, $idReader->getIdValue(...), $idReader);
            }

            // Otherwise, an incrementing integer is used as value automatically
            return null;
        };

        $emNormalizer = function (Options $options, $em) {
            if (null !== $em) {
                if ($em instanceof ObjectManager) {
                    return $em;
                }

                return $this->registry->getManager($em);
            }


Review comment (suggestion):
```suggestion
                        if ('' === $value = $idReader->getIdValue($object)) {
```

Code after:
            // field name. We can only use numeric IDs as names, as we cannot
            // guarantee that a non-numeric ID contains a valid form name
            if ($options['id_reader'] instanceof IdReader && $options['id_reader']->isIntId()) {
                return ChoiceList::fieldName($this, [__CLASS__, 'createChoiceName']);
            }

            // Otherwise, an incrementing integer is used as name automatically
            return null;
        };

        // The choices are always indexed by ID (see "choices" normalizer
        // and DoctrineChoiceLoader), unless the ID is composite. Then they
        // are indexed by an incrementing integer.
        // Use the ID/incrementing integer as choice value.
        $choiceValue = function (Options $options) {
            // If the entity has a single-column ID, use that ID as value
            if ($options['id_reader'] instanceof IdReader && $options['id_reader']->isSingleId()) {
                $idReader = $options['id_reader'];
                $uidFormat = $options['uid_format'];

                if (null === $uidFormat) {
                    return ChoiceList::value($this, $idReader->getIdValue(...), $idReader);
                }

                $formatMethod = match ($uidFormat) {
                    'base32' => 'toBase32',
                    'base58' => 'toBase58',
                    'binary' => 'toBinary',
                    'hex' => 'toHex',
                    'rfc4122' => 'toRfc4122',
                    default => throw new RuntimeException(sprintf('Unsupported value "%s" for "uid_format" option; valid values are "base32", "base58", "binary", "hex" and "rfc4122".', $uidFormat)),
                };

                return ChoiceList::value($this, static function (?object $object = null) use ($idReader, $formatMethod): string {
                    if ('' === $value = $idReader->getIdValue($object)) {
                        return '';
                    }

                    return Uuid::fromString($value)->$formatMethod();
                }, [$idReader, $uidFormat]);
            }

            // Otherwise, an incrementing integer is used as value automatically
            return null;
        };

        $emNormalizer = function (Options $options, $em) {
            if (null !== $em) {
                if ($em instanceof ObjectManager) {
                    return $em;
                }