Skip to content

Commit c32a422

Browse files
committed
Fix some deprecations related to Doctrine
1 parent 74c226b commit c32a422

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/Field/Configurator/CommonPreConfigurator.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace EasyCorp\Bundle\EasyAdminBundle\Field\Configurator;
44

55
use Doctrine\DBAL\Types\Types;
6+
use Doctrine\ORM\Mapping\FieldMapping;
67
use Doctrine\ORM\Mapping\JoinColumnMapping;
78
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
89
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
@@ -227,12 +228,16 @@ private function buildRequiredOption(FieldDto $field, EntityDto $entityDto): boo
227228

228229
// TODO: check if it's correct to never make a boolean value required
229230
// I guess it's correct because Symfony Forms treat NULL as FALSE by default (i.e. in the database the value won't be NULL)
230-
if (isset($entityDto->getClassMetadata()->fieldMappings[$field->getProperty()])
231-
&& Types::BOOLEAN === $entityDto->getClassMetadata()->getFieldMapping($field->getProperty())['type']) {
231+
// Doctrine ORM 2.x returns an array and Doctrine ORM 3.x returns a FieldMapping object
232+
$fieldMapping = $entityDto->getClassMetadata()->getFieldMapping($field->getProperty());
233+
// @phpstan-ignore-next-line (backward compatibility with Doctrine ORM 2.x)
234+
$fieldType = \is_array($fieldMapping) ? ($fieldMapping['type'] ?? null) : $fieldMapping->type;
235+
if (Types::BOOLEAN === $fieldType && isset($entityDto->getClassMetadata()->fieldMappings[$field->getProperty()])) {
232236
return false;
233237
}
234238

235-
$nullable = $entityDto->getClassMetadata()->fieldMappings[$field->getProperty()]['nullable'];
239+
// @phpstan-ignore-next-line (backward compatibility with Doctrine ORM 2.x)
240+
$nullable = \is_array($fieldMapping) ? ($fieldMapping['nullable'] ?? null) : $fieldMapping->nullable;
236241

237242
return false === $nullable || null === $nullable;
238243
}

src/Field/Configurator/DateTimeConfigurator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace EasyCorp\Bundle\EasyAdminBundle\Field\Configurator;
44

55
use Doctrine\DBAL\Types\Types;
6+
use Doctrine\ORM\Mapping\FieldMapping;
67
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
78
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldConfiguratorInterface;
89
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Intl\IntlFormatterInterface;
@@ -96,8 +97,11 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
9697
}
9798

9899
$fieldMapping = $entityDto->getClassMetadata()->getFieldMapping($field->getProperty());
100+
// Doctrine ORM 2.x returns an array and Doctrine ORM 3.x returns a FieldMapping object
101+
// @phpstan-ignore function.impossibleType, nullCoalesce.offset (backward compatibility with Doctrine ORM 2.x)
102+
$fieldType = \is_array($fieldMapping) ? ($fieldMapping['type'] ?? null) : $fieldMapping->type;
99103

100-
$isImmutableDateTime = \in_array($fieldMapping['type'], [Types::DATETIMETZ_IMMUTABLE, Types::DATETIME_IMMUTABLE, Types::DATE_IMMUTABLE, Types::TIME_IMMUTABLE], true);
104+
$isImmutableDateTime = \in_array($fieldType, [Types::DATETIMETZ_IMMUTABLE, Types::DATETIME_IMMUTABLE, Types::DATE_IMMUTABLE, Types::TIME_IMMUTABLE], true);
101105
if ($isImmutableDateTime) {
102106
$field->setFormTypeOptionIfNotSet('input', 'datetime_immutable');
103107
}

0 commit comments

Comments
 (0)