Skip to content

Commit 0804706

Browse files
committed
Refactor EntityMetadata and EntityConfigurator to remove targetEntityDisplayField and simplify display logic
1 parent 80c0cb4 commit 0804706

3 files changed

Lines changed: 13 additions & 33 deletions

File tree

psalm.baseline.xml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="6.14.2@bbd217fc98c0daa0a13aea2a7f119d03ba3fc9a0">
2+
<files psalm-version="6.14.3@d0b040a91f280f071c1abcb1b77ce3822058725a">
33
<file src="src/Controller/BaseCrudController.php">
44
<ArgumentTypeCoercion>
55
<code><![CDATA[$apply]]></code>
@@ -43,6 +43,10 @@
4343
<code><![CDATA[$entityInstance]]></code>
4444
</PossiblyNullArgument>
4545
<PossiblyNullReference>
46+
<code><![CDATA[getActionsConfig]]></code>
47+
<code><![CDATA[getActionsConfig]]></code>
48+
<code><![CDATA[getEditFormOptions]]></code>
49+
<code><![CDATA[getNewFormOptions]]></code>
4650
<code><![CDATA[setFieldAssets]]></code>
4751
<code><![CDATA[setFieldAssets]]></code>
4852
</PossiblyNullReference>
@@ -74,14 +78,6 @@
7478
<code><![CDATA[$field->getValue()]]></code>
7579
</MixedArgument>
7680
</file>
77-
<file src="src/Field/Configurator/EntityConfigurator/EntityMetadata.php">
78-
<MismatchingDocblockParamType>
79-
<code><![CDATA[string|(callable(object):string|TranslatableInterface|null)|null]]></code>
80-
</MismatchingDocblockParamType>
81-
<MismatchingDocblockReturnType>
82-
<code><![CDATA[string|(callable(object):string|TranslatableInterface|null)|null]]></code>
83-
</MismatchingDocblockReturnType>
84-
</file>
8581
<file src="src/Form/DataTransformer/EntityFieldDataTransformer.php">
8682
<MissingTemplateParam>
8783
<code><![CDATA[DataTransformerInterface]]></code>

src/Field/Configurator/EntityConfigurator.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
8282
Type\class_string(DashboardControllerInterface::class)->coerce($context->getDashboardControllerFqcn()),
8383
$targetCrudControllerFqcn,
8484
$targetEntityFqcn,
85-
EntityField::getEntityDisplayField($field),
8685
$field->getValue(),
8786
);
8887

@@ -98,10 +97,10 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
9897
throw new RuntimeException('Unknown association type.');
9998
}
10099

101-
if ($entityMetadata->targetEntityDisplayField() !== null) {
102-
// even if the entity has __toString method EntityType form type will not use it if option value is set to NULL.
103-
$field->setFormTypeOption('choice_label', $entityMetadata->targetEntityDisplayField());
104-
}
100+
$field->setFormTypeOption(
101+
'choice_label',
102+
fn (object $targetEntityInstance): string|null => EntityField::formatAsString($targetEntityInstance, $field, $this->translator),
103+
);
105104

106105
$autocompleteMode = Type\bool()->coerce($field->getCustomOption(EntityField::OPTION_AUTOCOMPLETE));
107106
$widgetMode = Type\string()->coerce($field->getCustomOption(EntityField::OPTION_WIDGET));

src/Field/Configurator/EntityConfigurator/EntityMetadata.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\CrudControllerInterface;
88
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface;
9-
use Symfony\Contracts\Translation\TranslatableInterface;
109

1110
/**
1211
* @psalm-immutable
@@ -27,33 +26,27 @@ final class EntityMetadata
2726
/** @var class-string */
2827
private string $targetEntityFqcn;
2928

30-
/** @var string|(callable(object):string|TranslatableInterface|null)|null */
31-
private $targetEntityDisplayField;
32-
3329
private object|int|string|null $targetEntityId;
3430

3531
/**
36-
* @param class-string<CrudControllerInterface> $sourceCrudControllerFqcn
37-
* @param class-string<DashboardControllerInterface> $targetDashboardControllerFqcn
38-
* @param class-string<CrudControllerInterface> $targetCrudControllerFqcn
39-
* @param class-string $targetEntityFqcn
40-
* @param string|(callable(object):string|TranslatableInterface|null)|null $targetEntityDisplayField
32+
* @param class-string<CrudControllerInterface> $sourceCrudControllerFqcn
33+
* @param class-string<DashboardControllerInterface> $targetDashboardControllerFqcn
34+
* @param class-string<CrudControllerInterface> $targetCrudControllerFqcn
35+
* @param class-string $targetEntityFqcn
4136
*/
4237
public function __construct(
4338
object|int|string|null $sourceEntityId,
4439
string $sourceCrudControllerFqcn,
4540
string $targetDashboardControllerFqcn,
4641
string $targetCrudControllerFqcn,
4742
string $targetEntityFqcn,
48-
string|callable|null $targetEntityDisplayField,
4943
object|int|string|null $targetEntityId,
5044
) {
5145
$this->sourceEntityId = $sourceEntityId;
5246
$this->sourceCrudControllerFqcn = $sourceCrudControllerFqcn;
5347
$this->targetDashboardControllerFqcn = $targetDashboardControllerFqcn;
5448
$this->targetCrudControllerFqcn = $targetCrudControllerFqcn;
5549
$this->targetEntityFqcn = $targetEntityFqcn;
56-
$this->targetEntityDisplayField = $targetEntityDisplayField;
5750
$this->targetEntityId = $targetEntityId;
5851
}
5952

@@ -94,14 +87,6 @@ public function targetEntityFqcn(): string
9487
return $this->targetEntityFqcn;
9588
}
9689

97-
/**
98-
* @return string|(callable(object):string|TranslatableInterface|null)|null
99-
*/
100-
public function targetEntityDisplayField(): string|callable|null
101-
{
102-
return $this->targetEntityDisplayField;
103-
}
104-
10590
public function targetEntityId(): object|int|string|null
10691
{
10792
return $this->targetEntityId;

0 commit comments

Comments
 (0)