Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
Disable entity autowire (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
kunicmarko20 committed Jan 17, 2019
1 parent df57ee9 commit 72002d0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ use App\Entity\Category;
* controller=CategoryController::class,
* entity=Category::class,
* adminCode="admin_code",
* autowireEntity=true,
* )
*/
class CategoryAdmin
Expand Down
5 changes: 5 additions & 0 deletions src/Annotation/AdminOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ final class AdminOptions
*/
public $controller;

/**
* @var bool
*/
public $autowireEntity = true;

public function getOptions(): array
{
return array_filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private function setDefaultValuesForAnnotation(AdminOptions $annotation, string
$annotation->adminCode = 'admin.' . Inflector::tableize($name);
}

if (!$annotation->entity) {
if (!$annotation->entity && $annotation->autowireEntity) {
[$annotation->entity, $managerType] = $this->findEntity($name);

if (!$annotation->managerType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace KunicMarko\SonataAutoConfigureBundle\Tests\DependencyInjection\Compiler;

use KunicMarko\SonataAutoConfigureBundle\Tests\Fixtures\Admin\DisableAutowireEntityAdmin;
use KunicMarko\SonataAutoConfigureBundle\Tests\Fixtures\Entity\Category;
use Doctrine\Common\Annotations\AnnotationReader;
use KunicMarko\SonataAutoConfigureBundle\DependencyInjection\Compiler\AutoConfigureAdminClassesCompilerPass;
use KunicMarko\SonataAutoConfigureBundle\DependencyInjection\SonataAutoConfigureExtension;
Expand Down Expand Up @@ -41,7 +43,7 @@ protected function setUp(): void
/**
* @dataProvider processData
*/
public function testProcess(string $admin, string $adminCode, array $tagOptions): void
public function testProcess(string $admin, ?string $entity, string $adminCode, array $tagOptions): void
{
$this->loadConfig([
'entity' => [
Expand Down Expand Up @@ -74,13 +76,19 @@ public function testProcess(string $admin, string $adminCode, array $tagOptions)
$tagOptions,
$adminDefinition->getTag('sonata.admin')[0]
);

$this->assertSame(
$entity,
$adminDefinition->getArgument(1)
);
}

public function processData(): array
{
return [
[
CategoryAdmin::class,
Category::class,
'admin.category',
[
'manager_type' => 'orm',
Expand All @@ -92,6 +100,7 @@ public function processData(): array
],
[
AnnotationAdmin::class,
Category::class,
'admin.annotation',
[
'manager_type' => 'orm',
Expand All @@ -101,6 +110,18 @@ public function processData(): array
'on_top' => false,
],
],
[
DisableAutowireEntityAdmin::class,
null,
'admin.disable_autowire_entity',
[
'manager_type' => 'orm',
'label' => 'Disable Autowire Entity',
'show_in_dashboard' => true,
'keep_open' => false,
'on_top' => false,
],
],
];
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Fixtures/Admin/DisableAutowireEntityAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace KunicMarko\SonataAutoConfigureBundle\Tests\Fixtures\Admin;

use KunicMarko\SonataAutoConfigureBundle\Annotation as Sonata;

/**
* @Sonata\AdminOptions(autowireEntity=false)
*
* @author Marko Kunic <kunicmarko20@gmail.com>
*/
class DisableAutowireEntityAdmin
{
}

0 comments on commit 72002d0

Please sign in to comment.