Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process deprecation of FieldDescriptionInterface::getTargetEntity() #6187

Merged
merged 1 commit into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Action/RetrieveAutocompleteItemsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private function retrieveFilterFieldDescription(
throw new \RuntimeException(sprintf('The field "%s" does not exist.', $field));
}

if (null === $fieldDescription->getTargetEntity()) {
if (null === $fieldDescription->getTargetModel()) {
throw new \RuntimeException(sprintf('No associated entity with field "%s".', $field));
}

Expand All @@ -212,7 +212,7 @@ private function retrieveFormFieldDescription(
throw new \RuntimeException(sprintf('The field "%s" does not exist.', $field));
}

if (null === $fieldDescription->getTargetEntity()) {
if (null === $fieldDescription->getTargetModel()) {
throw new \RuntimeException(sprintf('No associated entity with field "%s".', $field));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Action/SetObjectFieldValueAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function __invoke(Request $request): JsonResponse
if ('' !== $value
&& 'choice' === $fieldDescription->getType()
&& null !== $fieldDescription->getOption('class')
&& $fieldDescription->getOption('class') === $fieldDescription->getTargetEntity()
&& $fieldDescription->getOption('class') === $fieldDescription->getTargetModel()
) {
$value = $admin->getModelManager()->find($fieldDescription->getOption('class'), $value);

Expand Down
4 changes: 2 additions & 2 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1430,11 +1430,11 @@ public function attachAdminClass(FieldDescriptionInterface $fieldDescription)

$admin = $pool->getAdminByAdminCode($adminCode);
} else {
if (!$pool->hasAdminByClass($fieldDescription->getTargetEntity())) {
if (!$pool->hasAdminByClass($fieldDescription->getTargetModel())) {
return;
}

$admin = $pool->getAdminByClass($fieldDescription->getTargetEntity());
$admin = $pool->getAdminByClass($fieldDescription->getTargetModel());
}

if ($this->hasRequest()) {
Expand Down
6 changes: 3 additions & 3 deletions tests/Action/RetrieveAutocompleteItemsActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testRetrieveAutocompleteItemsActionDisabledFormelememt(): void
$this->admin->getFormFieldDescriptions()->willReturn(null);
$this->admin->getFormFieldDescription('barField')->willReturn($fieldDescription->reveal());

$fieldDescription->getTargetEntity()->willReturn(Foo::class);
$fieldDescription->getTargetModel()->willReturn(Foo::class);
$fieldDescription->getName()->willReturn('barField');

($this->action)($request);
Expand All @@ -120,7 +120,7 @@ public function testRetrieveAutocompleteItemsTooShortSearchString(): void
$this->admin->getFormFieldDescription('barField')->willReturn($fieldDescription->reveal());
$this->admin->getFormFieldDescriptions()->willReturn(null);
$targetAdmin->checkAccess('list')->willReturn(null);
$fieldDescription->getTargetEntity()->willReturn(Foo::class);
$fieldDescription->getTargetModel()->willReturn(Foo::class);
$fieldDescription->getName()->willReturn('barField');
$fieldDescription->getAssociationAdmin()->willReturn($targetAdmin->reveal());

Expand Down Expand Up @@ -241,7 +241,7 @@ private function configureAutocompleteItemsDatagrid(): ObjectProphecy
$datagrid->getPager()->willReturn($pager->reveal());
$pager->getResults()->willReturn([$model]);
$pager->isLastPage()->willReturn(true);
$fieldDescription->getTargetEntity()->willReturn(Foo::class);
$fieldDescription->getTargetModel()->willReturn(Foo::class);
$fieldDescription->getName()->willReturn('barField');
$fieldDescription->getAssociationAdmin()->willReturn($targetAdmin->reveal());

Expand Down
2 changes: 1 addition & 1 deletion tests/Action/SetObjectFieldValueActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function testSetObjectFieldValueActionOnARelationField(): void
$fieldDescription->getType()->willReturn('choice');
$fieldDescription->getOption('editable')->willReturn(true);
$fieldDescription->getOption('class')->willReturn(Bar::class);
$fieldDescription->getTargetEntity()->willReturn(Bar::class);
$fieldDescription->getTargetModel()->willReturn(Bar::class);
$fieldDescription->getAdmin()->willReturn($this->admin->reveal());
$fieldDescription->getTemplate()->willReturn('field_template');
$fieldDescription->getValue(Argument::cetera())->willReturn('some value');
Expand Down
5 changes: 5 additions & 0 deletions tests/App/Admin/FieldDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public function getTargetEntity()
return null;
}

public function getTargetModel()
{
return null;
}

public function setFieldMapping($fieldMapping)
{
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Controller/HelperControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function testSetObjectFieldValueActionOnARelationField(): void
$fieldDescription->getType()->willReturn('choice');
$fieldDescription->getOption('editable')->willReturn(true);
$fieldDescription->getOption('class')->willReturn(AdminControllerHelper_Bar::class);
$fieldDescription->getTargetEntity()->willReturn(AdminControllerHelper_Bar::class);
$fieldDescription->getTargetModel()->willReturn(AdminControllerHelper_Bar::class);
$fieldDescription->getAdmin()->willReturn($this->admin->reveal());
$fieldDescription->getTemplate()->willReturn('field_template');
$fieldDescription->getValue(Argument::cetera())->willReturn('some value');
Expand Down Expand Up @@ -426,7 +426,7 @@ public function testRetrieveAutocompleteItemsActionDisabledFormelememt(): void
$this->admin->getFormFieldDescriptions()->willReturn(null);
$this->admin->getFormFieldDescription('barField')->willReturn($fieldDescription->reveal());

$fieldDescription->getTargetEntity()->willReturn(Foo::class);
$fieldDescription->getTargetModel()->willReturn(Foo::class);
$fieldDescription->getName()->willReturn('barField');

$this->controller->retrieveAutocompleteItemsAction($request);
Expand All @@ -452,7 +452,7 @@ public function testRetrieveAutocompleteItemsTooShortSearchString(): void
$this->admin->getFormFieldDescription('barField')->willReturn($fieldDescription->reveal());
$this->admin->getFormFieldDescriptions()->willReturn(null);
$targetAdmin->checkAccess('list')->willReturn(null);
$fieldDescription->getTargetEntity()->willReturn(Foo::class);
$fieldDescription->getTargetModel()->willReturn(Foo::class);
$fieldDescription->getName()->willReturn('barField');
$fieldDescription->getAssociationAdmin()->willReturn($targetAdmin->reveal());

Expand Down Expand Up @@ -573,7 +573,7 @@ private function configureAutocompleteItemsDatagrid(): ObjectProphecy
$datagrid->getPager()->willReturn($pager->reveal());
$pager->getResults()->willReturn([$model]);
$pager->isLastPage()->willReturn(true);
$fieldDescription->getTargetEntity()->willReturn(Foo::class);
$fieldDescription->getTargetModel()->willReturn(Foo::class);
$fieldDescription->getName()->willReturn('barField');
$fieldDescription->getAssociationAdmin()->willReturn($targetAdmin->reveal());

Expand Down
5 changes: 5 additions & 0 deletions tests/Fixtures/Admin/FieldDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public function getTargetEntity(): void
// TODO: Implement getTargetEntity() method.
}

public function getTargetModel(): ?string
{
throw new \BadMethodCallException(sprintf('Implement %s() method.', __METHOD__));
}

public function setFieldMapping($fieldMapping): void
{
// TODO: Implement setFieldMapping() method.
Expand Down