Skip to content

Commit

Permalink
Fix issue 6904 by removing the subclass parameter from model auto com…
Browse files Browse the repository at this point in the history
…plete
  • Loading branch information
mpoiriert authored and jordisala1991 committed Jun 25, 2022
1 parent f79270e commit c362499
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
Expand Up @@ -114,11 +114,6 @@ file that was distributed with this source code.
'_sonata_admin': '{{ admin_code|e('js') }}',
{% endif %}
// subclass
{% if app.request.query.get('subclass') %}
'subclass': '{{ app.request.query.get('subclass') }}',
{% endif %}
{% if context == 'filter' %}
'field': '{{ full_name|replace({'filter[': '', '][value]': '', '__':'.'}) }}',
'_context': 'filter'
Expand Down
15 changes: 14 additions & 1 deletion tests/App/Admin/FooAdmin.php
Expand Up @@ -19,8 +19,10 @@
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType;
use Sonata\AdminBundle\Form\Type\TemplateType;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Tests\App\Model\Bar;
use Sonata\AdminBundle\Tests\App\Model\Foo;
use Symfony\Component\Form\Extension\Core\Type\TextType;

Expand Down Expand Up @@ -51,7 +53,18 @@ protected function configureFormFields(FormMapper $form): void
->add('customField', TemplateType::class, [
'template' => 'foo/custom_field.html.twig',
'parameters' => ['number' => 42],
]);
])
->add(
'referenced',
ModelAutocompleteType::class,
[
'class' => Bar::class,
'property' => ['name', 'title'],
],
[
'admin_code' => 'sonata_bar_admin',
]
);
}

protected function configureShowFields(ShowMapper $show): void
Expand Down
8 changes: 8 additions & 0 deletions tests/App/Model/Foo.php
Expand Up @@ -24,6 +24,8 @@ final class Foo implements EntityInterface
*/
private array $elements;

private ?Bar $referenced;

/**
* @param string[] $elements
*/
Expand All @@ -32,6 +34,7 @@ public function __construct(string $id, string $name, array $elements = [])
$this->id = $id;
$this->name = $name;
$this->elements = $elements;
$this->referenced = null;
}

public function getId(): string
Expand All @@ -44,6 +47,11 @@ public function getName(): string
return $this->name;
}

public function getReferenced(): ?Bar
{
return $this->referenced;
}

/**
* @return string[]
*/
Expand Down
18 changes: 18 additions & 0 deletions tests/Functional/Controller/CRUDControllerTest.php
Expand Up @@ -48,6 +48,24 @@ public function testCreate(): void
);
}

/**
* https://github.com/sonata-project/SonataAdminBundle/issues/6904.
*/
public function testCreateModelAutoCompleteNotPassingSubclassParameter(): void
{
$subclass = uniqid('subclass');
$client = static::createClient();
$crawler = $client->request(Request::METHOD_GET, '/admin/tests/app/foo/create?subclass='.$subclass);

static::assertSame(Response::HTTP_OK, $client->getResponse()->getStatusCode());

static::assertStringNotContainsString(
$subclass,
$crawler->filter('div[id$=_referenced]')->text(),
'The subclass parameter must no be present in referenced model auto complete ajax call'
);
}

public function testShow(): void
{
$client = static::createClient();
Expand Down

0 comments on commit c362499

Please sign in to comment.